def iterate_by_competition(self): iterator_driver = WebDriver() iterator_driver.get('https://sportzona.pl/app/events/list/sumo') competitions_iterator = SportZonaDownloader('event', iterator_driver) self.driver.close() self.driver = WebDriver() first_time = True for pages in range(competitions_iterator.get_number_of_pages()): for row in range(1, competitions_iterator.get_number_of_all_rows()): if first_time: for _ in range(self.start_page): competitions_iterator.got_to_next_page() sleep(0.5) first_time = False if self.skip_counter == 0: try: competitions_link = competitions_iterator.get_row_column_link( row, 1) print(competitions_link) self.driver.get(competitions_link) self.download_competitions() self.download_matches() except Exception as ex: print(ex) else: self.skip_counter -= 1 competitions_iterator.got_to_next_page() self.driver.close() self.driver = WebDriver()
def browser(): dir_path = os.path.dirname(os.path.realpath(__file__)) if os.name == 'nt': _browser = WebDriver(os.path.join(dir_path, "chromedriver.exe")) else: _browser = WebDriver(os.path.join(dir_path, "chromedriver")) yield _browser _browser.close() _browser.quit()
def setUpClass(cls): """ :return: """ super(FunctionTest, cls).setUpClass() try: cls.browser = WebDriver() except WebDriverException: cls.browser = WebDriver( executable_path='E:/chrome_driver/chromedriver.exe') finally: cls.browser.implicitly_wait(10)
def test_files(self): with open(SCREENSHOT_FILES) as file_pointer: testrunner = TestRunner.from_file(file_pointer) results = testrunner.run(WebDriver(CHROMEDRIVER)) self.assertEqual(results.files.keys(), ['test.png']) with open('/tmp/test.png', 'w') as file_pointer: copyfileobj(results.files['test.png'], file_pointer)
def setUpClass(cls): super().setUpClass() cls.selenium = WebDriver(executable_path='vendor/chromedriver') cls.selenium.implicitly_wait(0.5) thread_title_json = { "object": "value", "document": { "object": "document", "data": {}, "nodes": [ { "object": "block", "type": "paragraph", "data": {}, "nodes": [ { "object": "text", "text": "Thread0", "marks": [] } ] } ] } } # data setup cls.forum = Forum.objects.create(title="Forum0", description="Automatically generated forum.") cls.thread = Thread.objects.create(title=json.dumps(thread_title_json), author=None, forum=cls.forum) # Make dummy thread OP to keep thread invariant (every thread must have at least 1 post) p = Post(content="This is the OP.", thread = cls.thread); p.save();
def setUpClass(cls): super().setUpClass() # Capabilities provide access to JS console capabilities = DesiredCapabilities.CHROME capabilities['loggingPrefs'] = {'browser':'ALL'} cls.selenium = WebDriver(desired_capabilities=capabilities) cls.selenium.implicitly_wait(10)
def __init__(self): self.wd = WebDriver(executable_path='/usr/bin/chromedriver') # self.wd = WebDriver() self.wd.maximize_window() self.wd.implicitly_wait(15) self.session = SessionHelper(self) self.first_application = FirstApplicationHelper(self)
def test_yandex_search(): driver = WebDriver(executable_path='D:\work\chromedriver.exe') with allure.step('открываем страницу посика'): driver.get('https://ya.ru/') with allure.step('Ищем market.yandex.ru'): search_input = driver.find_element_by_id("text") search_button = driver.find_element_by_xpath( "//button[@type='submit']") search_input.send_keys("market.yandex.ru") search_button.click() def check_results_count(driver): inner_search_results = driver.find_elements_by_xpath( '//li[@class="serp-item"]') return len(inner_search_results) >= 10 with allure.step('Ожидаем, что количество результатов будет больше 10'): WebDriverWait(driver, 5, 0.5).until(check_results_count) with allure.step('Переходим по ссылке первого результата'): search_results = driver.find_elements_by_xpath( '//li[@class="serp-item"]') link = search_results[0].find_elements_by_xpath('.//h2/a]') link.click() driver.switch_to.window(driver.window_handles[1]) with allure.step('Проверяем тайтл'): assert driver.title == 'Яндекс.Маркет — выбор и покупка товаров из проверенных интернет-магазинов'
def setUpClass(cls): super().setUpClass() cls.selenium = WebDriver(options=chrome_options) cls.selenium.implicitly_wait(10) cls.webdev = pexpect.spawn('webdev serve', cwd='dart_test_app') cls.webdev.logfile = sys.stdout.buffer cls.webdev.expect('Succeeded', timeout=90)
def test_351(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') one = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '1']") two = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '2']") five = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '5']") dot = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '.']") c = driver.find_element_by_xpath( "//ul[@class = 'operations']/li[text() = 'C']") with allure.step('Клик по кнопке "2"'): two.click() with allure.step('Клик по кнопке "1"'): one.click() with allure.step('Клик по кнопке "точка"'): dot.click() with allure.step('Клик по кнопке "5"'): five.click() with allure.step('Клик по кнопке "C"'): c.click() with allure.step('Проверка наличия "0" в поле ввода данных'): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == '0'
def test_lamoda_change_city(): driver = WebDriver(executable_path='C://python//chromedriver.exe') driver.implicitly_wait(10) city_name = "г Новосибирск" with allure.step('Открываем страницу сайта Ламода'): driver.get('https://lamoda.ru') with allure.step('Нажимаем на кнопку выбора региона доставки'): search_button = driver.find_element_by_xpath('//span[@class="header__top-description"]').click() with allure.step('Выбираем окно ввода и набираем г Новосибирск'): search_input = driver.find_element_by_xpath('//input[@class="text-field text-field_large"]').send_keys( "г Новосибирск") city = 'г Новосибирск' with allure.step('Выбираем г Новосибирск из списка саджестов'): suggests = driver.find_elements_by_xpath('//ul[@class="geo__suggest"]//li[@class="suggest__item"]') for suggest in suggests: if suggest.find_element_by_xpath('//span[@class="suggest__item-query"]').text == city: suggest.click() break else: raise Exception(f'Среди подсказок отсутствует {city_name}') with allure.step('Нажимаем подтвержить выбор'): search_button = driver.find_element_by_xpath('//button[@class="button button_blue geo__button-save"]').click() with allure.step('Перезагружаем страницу'): driver.refresh() with allure.step('Проверяем что выбор города сохранился после перезагрузки страницы'): search_current_city = driver.find_element_by_xpath( '*//span[@class="header__top-description-region-name arrow-bottom arrow-bottom_geo"][contains( text(),"г Новосибирск")]') assert search_current_city.text == "г Новосибирск"
def test_331(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') five = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '5']") nine = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '9']") multiplier = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = 'x']") equal = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '=']") with allure.step('Клик по кнопке "5"'): five.click() with allure.step('Клик по кнопке "X"'): multiplier.click() with allure.step('Клик по кнопке "9"'): nine.click() with allure.step('Клик по кнопке "="'): equal.click() with allure.step('Проверка выполнения операции умножения'): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == '45'
def test_343(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') eight = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '8']") zero = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '0']") divider = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '/']") equal = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '=']") with allure.step('Клик по кнопке "8"'): eight.click() with allure.step('Клик по кнопке "/"'): divider.click() with allure.step('Клик по кнопке "0"'): zero.click() with allure.step('Клик по кнопке "="'): equal.click() with allure.step('Проверка выполнения операции деления'): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == 'Error'
def test_321(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') one = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '1']") two = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '2']") nine = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '9']") minus = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '-']") equal = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '=']") with allure.step('Клик по кнопке "1"'): one.click() with allure.step('Клик по кнопке "-"'): minus.click() with allure.step('Клик по кнопке "2"'): two.click() with allure.step('Клик по кнопке "9"'): nine.click() with allure.step('Клик по кнопке "2"'): two.click() with allure.step('Клик по кнопке "="'): equal.click() with allure.step('Проверка выполнения операции вычитания'): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == '-291'
def test_222(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') one = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '1']") four = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '4']") five = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '5']") dot = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '.']") with allure.step('Клик по кнопке "1"'): one.click() with allure.step('Клик по кнопке "1"'): one.click() with allure.step('Клик по кнопке "точка"'): dot.click() with allure.step('Клик по кнопке "5"'): five.click() with allure.step('Клик по кнопке "4"'): four.click() with allure.step('Клик по кнопке "точка"'): dot.click() with allure.step('Клик по кнопке "1"'): one.click() with allure.step( 'Проверка наличия десятичной дроби "11.541" в поле ввода данных' ): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == '11.541'
def shell_setup(): global driver global _username global _password driver = WebDriver() driver.implicitly_wait(20) driver.get('http://192.168.5.47:8889/login/') _username = "******" _password = "******" username_input = driver.find_element_by_name("username") username_input.send_keys(_username) password_input = driver.find_element_by_name("password") password_input.send_keys(_password) driver.find_element_by_id('login').click() driver.get('http://192.168.5.47:8889/create_survey/') # add survey name driver.find_element_by_id("survey-name").send_keys(faker.word()) driver.find_element_by_id("next").click() # add survey group driver.find_element_by_id("survey-group").send_keys(faker.word()) driver.find_element_by_id("next").click() # select question _ul = driver.find_element_by_xpath("//ul[contains(@id, 'me-select-list')]") _li = _ul.find_elements_by_tag_name("li") to_be_select_li = [_li[random.randint(1, len(_li) - 1)] for i in range(random.randint(1, len(_li) - 2))] _sleep(2) [i.click() for i in set(to_be_select_li)] driver.find_element_by_id("next").click() # select date start_date = faker.date_between(start_date='-1m', end_date='+1w').strftime('%Y/%m/%d') end_date = faker.date_between(start_date='+2w', end_date='+1y').strftime('%Y/%m/%d') driver.find_element_by_id("survey-start-time").send_keys("{} 00:59".format(start_date)) driver.find_element_by_id("survey-start-time").send_keys(start_date) driver.find_element_by_id("survey-end-time").send_keys("{} 00:59".format(start_date)) driver.find_element_by_id("survey-end-time").send_keys(end_date)
def test_yandex_search(): driver = WebDriver(executable_path='D://allure//chromedriver.exe') with allure.step('Открываем страницу яндекса'): driver.get('https://ya.ru') with allure.step('Ищем Виталия Милонова'): search_input = driver.find_element_by_xpath('//input[@id="text"]') search_button = driver.find_element_by_xpath( '//div[@class="search2__button"]//button[@type="submit"]') search_input.send_keys('Виталий Милонов') search_button.click() def check_results_count(driver): search_results = driver.find_elements_by_xpath( '//li[@class="serp-item"]') return len(search_results) >= 10 with allure.step('Ожидаем, что количество результатов теста больше 10'): WebDriverWait(driver, 5, 0.5).until(check_results_count, 'Количество результатов поиска меньше 10') with allure.step('Переходим по ссылке первого результата'): search_results = driver.find_elements_by_xpath( '//li[@class="serp-item"]') link = search_results[0].find_element_by_xpath('.//h2/a') link.click() driver.switch_to.window(driver.window_handles[1]) with allure.step('Проверяем корректность Title страницы'): assert driver.title == 'Милонов, Виталий Валентинович — Википедия'
def test_361(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') two = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '2']") seven = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '5']") nine = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '.']") ac = driver.find_element_by_xpath( "//ul[@class = 'operations']/li[text() = 'AC']") with allure.step('Клик по кнопке "2"'): two.click() with allure.step('Клик по кнопке "9"'): nine.click() with allure.step('Клик по кнопке "7"'): seven.click() with allure.step('Клик по кнопке "AC"'): ac.click() with allure.step('Проверка наличия "0" в поле ввода данных'): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == '0'
def google(self, **kwargs): url = "http://www.google.com" keywords = kwargs.pop('keyword', None) driver = WebDriver( executable_path=os.path.join(BASE_DIR, 'driver', 'chromedriver')) wait_driver = WebDriverWait(driver=driver, timeout=30) try: print("Start SeoRobot Google") driver.get(url) # Url de la pagina a Buscar driver.find_element_by_name('q').send_keys(keywords, Keys.ENTER) time.sleep(10) links = driver.find_elements_by_css_selector('.rc > .r a') print("end") finally: print("Finished SeoRobot Google") result = { "result": dict([(i, _.get_attribute('href')) for i, _ in enumerate(links, 1)]) } driver.quit() return result
def driver(request): print('start fixture') chrome_driver = WebDriver(executable_path='D://selenium//chromedriver.exe') chrome_driver.implicitly_wait(3) yield chrome_driver print('stop fixture') chrome_driver.close()
def setup(): print("------- start driver_fixture ---------") driver = WebDriver() driver.implicitly_wait(5) yield driver print("------- stop driver_fixture ---------") driver.close()
def __init__(self, email, password, url, post_text, image): self.email = email self.password = password self.url = url self.post_text = post_text self.image = image options = Options() options.headless = True self.driver = WebDriver(executable_path='driver/chromedriver.exe', port=0, options=options, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None, keep_alive=True) # driver = webdriver.Chrome("drivers/chromedriver.exe", chrome_options=options) self.driver.get("https://www.facebook.com") email_entry_field = self.driver.find_element_by_id("email") email_entry_field.send_keys(self.email) password_entry_field = self.driver.find_element_by_id("pass") password_entry_field.send_keys(self.password) confirm_button = self.driver.find_element_by_id("u_0_b") confirm_button.send_keys(Keys.ENTER) self.access_group() time.sleep(3)
def test_37(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') plus = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '+']") minus = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '-']") multiplier = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = 'x']") divider = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '/']") with allure.step('Клик по кнопке "+"'): plus.click() with allure.step('Клик по кнопке "-"'): minus.click() with allure.step('Клик по кнопке "X"'): multiplier.click() with allure.step('Клик по кнопке "/"'): divider.click() with allure.step('В поле ввода пусто'): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == ''
def setUpClass(cls) -> None: cls.url = MAIN_URL_HOME cls.driver = WebDriver(CHROME_DRIVER_LOCATION) cls.driver.get(cls.url) cls.driver.maximize_window() data = {"user": "******", "pass": "******", "value": "99"} admin_setting_completenss_helper(cls.driver, data)
def test_42(self): with allure.step( 'Переход на веб-страницу http://qa-test.klika-tech.com'): driver = WebDriver( executable_path='C://Selenium//chromedriver.exe') driver.get('http://qa-test.klika-tech.com') four = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '4']") seven = driver.find_element_by_xpath( "//ul[@class = 'digits']/li[text() = '7']") plus = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '+']") equal = driver.find_element_by_xpath( "// ul[ @class = 'operations'] / li[text() = '=']") with allure.step('Клик по кнопке "7"'): seven.click() with allure.step('Клик по кнопке "+"'): plus.click() with allure.step('Клик по кнопке "4"'): four.click() with allure.step('Клик по кнопке "="'): equal.click() with allure.step('Клик по кнопке "="'): equal.click() with allure.step('В поле ввода чисто "15"'): displayresult = driver.find_element_by_xpath( "// div[ @class = 'display']") assert displayresult.text == '15'
def get_link(self, query, s_date, e_date): self.query = query self.s_date=s_date self.e_date=e_date options = webdriver.ChromeOptions() options.add_argument( "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36") options.add_argument('headless') options.add_argument('--disable-gpu') options.add_argument('lang=ko_KR') browser = WebDriver(executable_path='D:\python_workspace\pyTextMiner\selenium_server\chromedriver.exe', options=options) #browser = WebDriver(executable_path='/usr/lib/chromium-browser/chromedriver', options=options) url = "https://m.search.naver.com/search.naver?where=m_blog&sm=mtb_opt&query=" + query + "&display=15&st=sim&nso=p%3Afrom" + s_date + "to" + e_date browser.get(url) browser.implicitly_wait(random.randrange(5,10)) SCROLL_PAUSE_TIME = 1.5 # Get scroll height last_height = browser.execute_script("return document.body.scrollHeight") while True: # Scroll down to bottom browser.execute_script("window.scrollTo(0, document.body.scrollHeight);") # Wait to load page time.sleep(SCROLL_PAUSE_TIME) # Calculate new scroll height and compare with last scroll height new_height = browser.execute_script("return document.body.scrollHeight") if new_height == last_height: cont = browser.page_source soup = BeautifulSoup(cont, 'html.parser') for urls in soup.select(".total_dsc"): if urls["href"].startswith("https://m.blog.naver.com") or 'blog.me' in urls["href"]: self.ab_url.append(urls['href']) break last_height = new_height time.sleep(random.randrange(5,15))
def setUpClass(cls): super(QuestionDetailViewUi, cls).setUpClass() chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=1920x1080") cls.selenium = WebDriver(chrome_options=chrome_options) cls.selenium.implicitly_wait(10)
def setUpClass(cls): print("Setting Up...") super().setUpClass() cls.selenium = WebDriver() cls.selenium.implicitly_wait(10) cls.selenium.get('%s%s' % (cls.live_server_url, '/')) # username_input = cls.selenium.find_element_by_xpath("/html/body/div/form/div[4]/a").click() cls.selenium.find_element_by_xpath("/html/body/div/form/div[4]/a").click() # username_input = cls.selenium.find_element_by_name("username") # username_input.send_keys('crystal') cls.selenium.find_element_by_name("username").send_keys(username) # password_input = cls.selenium.find_element_by_name("first_password") # password_input.send_keys('yeohje00') cls.selenium.find_element_by_name("first_password").send_keys(password) # password_input = cls.selenium.find_element_by_name("password") # password_input.send_keys('yeohje00') cls.selenium.find_element_by_name("password").send_keys(password) # username_input = cls.selenium.find_element_by_xpath("/html/body/div/form/div[1]/button").click() cls.selenium.find_element_by_xpath("/html/body/div/form/div[1]/button").click() # cls.selenium.get('%s%s' % (cls.live_server_url, '/accounts/login/')) print("Setting Up Done...")
def __init__(self, IsUserChrome: bool = True, IsProxy: bool = False, timeout: int = 10, is_load_img=True, proxy: str = ''): self.timeout = timeout chromeOpitons = Options() prefs = { "profile.managed_default_content_settings.images": 1 if is_load_img else 2, "profile.content_settings.plugin_whitelist.adobe-flash-player": 1, "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1, } chromeOpitons.add_experimental_option('prefs', prefs) if proxy != "": chromeOpitons.add_argument('--proxy-server=http://%s' % proxy) if IsUserChrome: self.Chrome = WebDriver(chrome_options=chromeOpitons) self.IsProxy = IsProxy self.ProxyIpList = list() self.ResetBackWebBrowser() urllib3.disable_warnings() if IsProxy: self.proxy_thread = threadByQueue(10, target=self.check_proxy, args=self.GetWebProxyIpList()) self.proxy_thread.start()
def browser(request): language = request.config.getoption("language") language == "en" browser: WebDriver() = webdriver.Chrome( executable_path=ChromeDriverManager().install()) yield browser browser.quit()