'Scenario: Ensure that the course creation with an existing org should be successful.
Given I have filled course creation form with an existing org and all required fields
And I selected `Course Organization` input via autocomplete
When I click \'Create\' button
Form validation should pass
Then I see the course listing page with newly created course'

def test_create_course_with_existing_org_via_autocomplete(self):

    self.auth_page.visit()
    self.dashboard_page.visit()
    new_org = 'orgX2'
    self.assertFalse(self.dashboard_page.has_course(org=new_org, number=self.course_number, run=self.course_run))
    self.assertTrue(self.dashboard_page.new_course_button.present)
    self.dashboard_page.click_new_course_button()
    self.assertTrue(self.dashboard_page.is_new_course_form_visible())
    self.dashboard_page.fill_new_course_form(self.course_name, '', self.course_number, self.course_run)
    self.dashboard_page.course_org_field.fill('org')
    self.dashboard_page.select_item_in_autocomplete_widget(new_org)
    self.assertTrue(self.dashboard_page.is_new_course_form_valid())
    self.dashboard_page.submit_new_course_form()
    course_outline_page = CourseOutlinePage(self.browser, new_org, self.course_number, self.course_run)
    course_outline_page.visit()
    course_outline_page.wait_for_page()
    self.dashboard_page.visit()
    self.assertTrue(self.dashboard_page.has_course(org=new_org, number=self.course_number, run=self.course_run))
