class BaseTestClass(): """ Contextual help test """ def run_sql(self, db_instance, script): "run psql <script.sql> on db_instance (eg '00')" for i in ['PGHOST', 'PGPORT', 'PGDATABASE', 'PGUSER', 'PGPASSWORD']: os.environ[i] = os.environ[i + '_' + db_instance] returncode = call([ 'sh', '-c', 'psql -v ON_ERROR_STOP=1 < ' + DB_DIR + '/' + script + '.sql > /dev/null' ]) if returncode != 0: raise Exception("Error: DB script failed (" + DB_DIR + '/' + script + ".sql)") def set_etsy_testcase(self, tc_name): url = self.etsy_url + '/set_test_id?test_id=' + tc_name r = requests.get(url) sleep(1) if r.status_code != 200: raise Exception("Error: cannot set test case on " + url) def setup_class(self): # shishito / selenium support self.tc = ShishitoSupport().get_test_control() self.driver = self.tc.start_browser() self.ts = SeleniumTest(self.driver) self.etsy_host = os.environ['ETSY_HOST'] self.etsy_port = os.environ['ETSY_PORT'] self.etsy_url = 'http://' + self.etsy_host + ':' + self.etsy_port # etsy url - create sql script to update cfg with open(DB_DIR + "/tmp-etsy-location.sql", "w+") as f: f.write("INSERT INTO config (id, value) values ('etsy_host', '" + self.etsy_host + "');\n") f.write("INSERT INTO config (id, value) values ('etsy_port', '" + self.etsy_port + "');\n") self.run_sql(self, '00', 'clean_db_00') self.run_sql(self, '00', 'tmp-etsy-location') # restart node if call([BIN_DIR + '/restart_node']) != 0: raise Exception("Error: Node restart failed (" + BIN_DIR + "/restart_node)") sleep(2) # Set base URL - host taken from env. prod_host = os.environ[ 'PRODUCT_HOST'] if 'PRODUCT_HOST' in os.environ else '127.0.0.1' self.base_url = 'http://' + prod_host + '/' def setup_method(self, method): # reset DB instance 00 self.run_sql('00', 'clean_db_00') self.run_sql('00', 'tmp-etsy-location') self.driver.get(self.base_url) def teardown_class(self): self.tc.stop_browser() pass def teardown_method(self, method): self.tc.stop_test( get_test_info()) # save screenshot in case test fails
class TestMainPage(): """ Contextual help test """ def setup_class(self): self.tc = ShishitoSupport().get_test_control() self.driver = self.tc.start_browser() self.ts = SeleniumTest(self.driver) # Page Objects self.search_page = GoogleSearch(self.driver) self.doodles = GoogleDoodles(self.driver) def teardown_class(self): self.tc.stop_browser() def setup_method(self, method): self.tc.start_test(True) def teardown_method(self, method): test_info = get_test_info() self.tc.stop_test(test_info) ### Tests ### @pytest.mark.smoke def test_google_search(self): """ test google search """ self.ts.click_and_wait(self.search_page.luck) self.ts.click_and_wait(self.doodles.doodle_archive) Assert.equal(self.driver.title, 'Google Doodles') def test_failing(self): """ test google title """ # self.execution_id = self.tc.get_execution_id("MET-11") Assert.equal(self.driver.title, 'Yahoo') def test_good_title(self): """ test google title """ self.search_page.search_field.send_keys('Jaromir Jagr') self.ts.click_and_wait(self.search_page.search_button) time.sleep(3) Assert.equal(self.search_page.jagr_title.text, u'Jaromír Jágr')
class TestMainPage(): """ Contextual help test """ def setup_class(self): self.tc = ShishitoSupport().get_test_control() self.driver = self.tc.start_browser() self.ts = SeleniumTest(self.driver) def teardown_class(self): self.tc.stop_browser() def setup_method(self, method): self.tc.start_test(True) def teardown_method(self, method): self.tc.stop_test(get_test_info()) ### Tests ### @pytest.mark.smoke def test_google_search(self): """ test google search """ Assert.equal(self.driver.title, 'Google')
class TestMainPage(): """ Contextual help test """ def setup_class(self): self.tc = ShishitoSupport().get_test_control() self.driver = self.tc.start_browser() self.ts = SeleniumTest(self.driver) def teardown_class(self): self.tc.stop_browser() def setup_method(self, method): self.tc.start_test(True) def teardown_method(self, method): self.tc.stop_test(get_test_info()) ### Tests ### @pytest.mark.smoke def test_google_search(self): """ test google search """ Assert.equal(self.driver.title, 'Google')
class BaseTestClass(): """ Contextual help test """ def set_etsy_testcase(self, tc_name): etsy_emulator_interface = EtsyEmulatorInterface() for _ in range(5): try: etsy_emulator_interface.set_test_case(tc_name) break except EtsyEmulatorRequestError: etsy_emulator_interface.restart_emulator() else: # last attempt etsy_emulator_interface.set_test_case(tc_name) def restart_node(self, instance='00'): if call([BIN_DIR + '/restart_node', instance]) != 0: raise Exception("Error: Node restart failed (" + BIN_DIR + "/restart_node)") sleep(2) def stop_all(self): cmd = os.path.join(BIN_DIR, 'default', 'restart-product') for _ in range(3): if call([cmd, '--kill']) == 0: sleep(2) return raise Exception("Error: Nodes kill failed (" + cmd + " --kill)") def restart_all(self): os.environ[ 'QA_CURRENT_TEST'] = self.__module__ + '.py ' + self.test_id if hasattr( self, 'test_id') else self.__module__ + '.py' cmd = os.path.join(BIN_DIR, 'default', 'restart-product') for full_restart in range(5): for _ in range(10): if call([cmd]) == 0: sleep(2) break else: raise Exception("Error: Nodes restart failed (" + cmd + ")") # check if we can connect for connect_attempt in range(10, -1, -1): try: r1 = requests.get(self.base_url, allow_redirects=False) r2 = requests.get(self.login_url_http, allow_redirects=False) if r1.status_code == 302 and r2.status_code == 302: print("restart_all: servers are running", self.base_url, self.login_url_http) sleep(1) return print("restart_all: cannot get", self.base_url, "status_code =", r1.status_code, self.login_url_http, "status_code =", r2.status_code) except Exception as e: print("restart_all: error getting", self.base_url, self.login_url_http, e.args) if connect_attempt > 0: sleep(1) raise Exception('Error: restart_all failed, no attempt left') def setup_class(self): # shishito / selenium support self.tc = ShishitoSupport().get_test_control() try: # Set base URL - host taken from env. prod_host = os.environ[ 'QA_PRODUCT_HOST'] if 'QA_PRODUCT_HOST' in os.environ else '127.0.0.1' prod_port = os.environ[ 'QA_WEB_HTTPS_PORT'] if 'QA_WEB_HTTPS_PORT' in os.environ else '80' login_host = os.environ[ 'QA_PRODUCT_HOST_AUTH'] if 'QA_PRODUCT_HOST_AUTH' in os.environ else prod_host self.base_url = 'https://' + prod_host + ':' + prod_port + '/' # Login URLs self.login_url_http = 'http://' + login_host + ':' + os.environ[ 'QA_AUTH_HTTP_PORT'] + '/' self.login_url_https = 'https://' + login_host + ':' + os.environ[ 'QA_AUTH_HTTPS_PORT'] + '/' self.web_api_url_https = 'https://' + prod_host + ':' + prod_port + '/api/v1/' except: print('*** setup_class failed ***') raise def setup_method(self, method): self.test_id = method.__name__ # start browser for attempt in range(20): try: print('*** setup_method: starting browser ***') self.driver = self.tc.start_browser() break except WebDriverException as e: print("Cannot connect to Webdriver.\n" + str(e)) sleep(5) else: assert False, "Test could not be run due to the Webdriver error" self.ts = SeleniumTest(self.driver) def teardown_method(self, method): print('*** teardown_method: stopping browser ***') try: console_events = self.driver.get_log('browser') except Exception as e: print('ERROR: failed to get console events: ' + str(e)) console_events = {} try: self.tc.stop_test(get_test_info(), debug_events=console_events ) # save screenshot in case test fails except Exception as e: print('ERROR: failed to stop the test: ' + str(e)) try: self.tc.stop_browser() except Exception as e: print('ERROR: failed to stop the browser: ' + str(e)) print('*** teardown_method: ended successfully ***') def close_intercom(self): """ try to find intercom close button (if exists), click it """ d = self.driver window_selectors = ['div.intercom-chat-composer', 'intercom-block'] button_selectors = [ 'div.intercom-chat-dismiss-button', 'div.intercom-launcher-hovercard-close' ] # move to the IC window, so that the close button is displayed for selector in window_selectors: try: win = d.find_element_by_css_selector(selector) action = ActionChains(d) action.move_to_element(win) action.perform() except: pass for selector in button_selectors: try: b = d.find_element_by_css_selector(selector) click(b) except: pass
class TestWelcomeGuide(): """ Test Adblock Browser Welcome Guide """ def setup_class(self): self.tc = ShishitoSupport().get_test_control() self.driver = self.tc.start_browser() self.ts = SeleniumTest(self.driver) self.welcome_guide = WelcomeGuide(self.driver) self.bottom_bar = BottomBar(self.driver) self.url_bar = UrlBar(self.driver) self.tabs_page = TabsPage(self.driver) self.main_page = MainPage(self.driver) self.bookmarks_page = BookmarksPage(self.driver) self.dashobard_page = DashboardPage(self.driver) self.history_page = HistoryPage(self.driver) self.test_url = "google.com" def teardown_class(self): self.tc.stop_browser() def setup_method(self, method): self.tc.start_test(True) def teardown_method(self, method): test_info = get_test_info() self.tc.stop_test(test_info) ### Tests ### @pytest.mark.smoke def test_1welcome_guide(self): self.welcome_guide.skip_guide() Assert.true(self.ts.is_element_visible(self.bottom_bar._menu_icon)) def test_2open_site(self): """Test check if I can load page in app""" self.ts.click_and_wait(self.url_bar.address_field) Assert.true(self.ts.is_element_visible(self.url_bar._cancel)) Assert.true( self.ts.is_element_visible(self.main_page._keyboard_locator)) url_replace_text = self.url_bar.address_field_text.text self.url_bar.address_field_text.send_keys(self.test_url) self.ts.click_and_wait(self.main_page.go_button) url_text = self.url_bar.address_field_text.text self.ts.click_and_wait(self.bottom_bar.bookmarks_icon) Assert.not_equal(url_text, url_replace_text, 'Site is not loaded') def test_3new_tab_dialog(self): #Test check if user click on new tab button - dialog is shown with plus icon self.ts.click_and_wait(self.bottom_bar.tabs_icon) self.ts.click_and_wait(self.tabs_page.plus_button) self.ts.click_and_wait(self.bottom_bar.tabs_icon) Assert.equal(len(self.tabs_page.tabs_list), 2, 'New tab is not created') def test_4bookmark_dialog(self): #Test open bookmarks dialig, need to add later assertion for added site self.ts.click_and_wait(self.bottom_bar.tabs_icon) self.ts.click_and_wait(self.main_page.bookmark_button) Assert.true( self.ts.is_element_visible(self.bookmarks_page._bookmark_dialog)) #TODO Assertions checking that site added to bookmarks def test_5dashboard_dialog(self): #Test open dashboard dialig, need to add later assertion for added site self.ts.click_and_wait(self.main_page.dashboard_button) Assert.true( self.ts.is_element_visible(self.dashobard_page._dashboard_dialog)) #TODO Assertions checking that site added to dashboards def test_6history_dialog(self): #Test open history dialig, need to add later assertion for loaded site self.ts.click_and_wait(self.main_page.history_button) Assert.true( self.ts.is_element_visible(self.history_page._history_dialog))