Я в автотестировании новичок, столкнулась с тем, что ни один метод verify, а так же методы get url и get location не работает при запуске теста.
Виной мой код или новый селениум? (УРЛ в коде заменила)
Хочу сделать проверку, что пользователь находится на нужной страницк
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.support.ui import WebDriverWait
import unittest, time, re
from selenium.webdriver.support import expected_conditions as EC
class TestProBookTour(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://some_url.com"
self.verificationErrors = []
self.accept_next_alert = True
def test_booking(self):
driver = self.driver
# open main
driver.get(self.base_url)
self.assertIn('Tours', self.driver.title)
# click on geographies field choose 1st geography
driver.find_element_by_xpath("(//form[@id='id_search_form_main']/ul/li/div/div)[7]").click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".main__search ul:nth-child(2) > li:first-child div.selectize-dropdown-content div.optgroup > div:first-child")))
driver.find_element_by_css_selector(".main__search ul:nth-child(2) > li:first-child div.selectize-dropdown-content div.optgroup > div:first-child").click()
# check if elements are selected
self.assertIn(u'мес', self.driver.find_element_by_css_selector(".main__search div.selectize-items-count").text, "Element is NOT here!")
# click on activities field choose 4 first activities
driver.find_element_by_css_selector(".main__search ul:nth-child(2) > li:nth-child(2) > div:nth-child(2) > div:nth-child(1)").click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//div[2]/div/form/ul/li[2]/div/div[2]/div/div[1]")))
driver.find_element_by_xpath("//div[2]/div/form/ul/li[2]/div/div[2]/div/div[1]").click()
driver.find_element_by_xpath("//div[2]/div/form/ul/li[2]/div/div[2]/div/div[2]").click()
driver.find_element_by_xpath("//div[2]/div/form/ul/li[2]/div/div[2]/div/div[3]").click()
driver.find_element_by_xpath("//div[2]/div/form/ul/li[2]/div/div[2]/div/div[4]").click()
driver.find_element_by_css_selector(".main__search ul:nth-child(2) > li:nth-child(3) > div:nth-child(2) > div:nth-child(1)").click()
# check if elements are selected
self.assertIn(u'месяц', self.driver.find_element_by_css_selector(".main__search div:nth-child(1)").text,
"Element is NOT here!")
# self.fail('Finish the test!')
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//div[2]/div/form/ul/li[3]/div/div[2]/div[2]/div[1]/div[1]")))
driver.find_element_by_xpath("//div[2]/div/form/ul/li[3]/div/div[2]/div[2]/div[1]/div[1]").click()
# check if elements are selected
self.assertIn(u'актив', self.driver.find_element_by_css_selector(".main__search div:nth-child(1)").text,
"Element is NOT here!")
driver.find_element_by_css_selector(".main__search button.search__submit").click()
# **Вот, в какой строке проблема**
self.driver.verifyTextPresent('search' or 'tour', self.driver.current_url.text)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
# def tearDown(self):
# self.driver.quit()
# self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()