Для каждого метода вызывается хромдрайвер.
Задача:
1 раз вызвать хром драйвер и дальше для каждого метода открывать главную страницу “tion.com”.
Сейчас для каждого метода вызывается хромдрайвер.
Подскажите как изменить код. Спасибо.
Код
class basic_functions(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(executable_path = r"E:/chromedriver.exe")
self.driver.get("http://tion.com")
self.driver.set_window_size(1920,1080)
def test_authorization_email_not_registered(self):
self.driver.get("http://tion.com")
WebDriverWait(self.driver, 10)
try:
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".header__nav-item.ng-scope"))).click()
self.driver.find_element_by_css_selector(".header__nav-item.ng-scope").click()
# filling email; password
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "email")))
self.driver.find_element_by_name("email").send_keys("not_registered@psyquation.com")
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "password")))
self.driver.find_element_by_name("password").send_keys("159753")
WebDriverWait(self.driver, 10)
self.driver.find_element_by_css_selector(".form-login__submit").click()
# check error message under form
error_msg = self.driver.find_element_by_xpath("/html/body/main/div/div/div/form/div[2]/div/div")
WebDriverWait(self.driver, 10).until(error_msg).is_displayed()
# clean Login form
self.driver.find_element_by_name("email").clear()
self.driver.find_element_by_name("password").clear()
# check error message disappeared after form is cleaned
WebDriverWait(self.driver, 10).until_not(error_msg).is_displayed()
except TimeoutException:
print ("No such element in test_authorization_email_not_registered test")
def test_authorization_empty_email_field(self):
self.driver.get("http://tion.com")
WebDriverWait(self.driver, 10)
try:
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".header__nav-item.ng-scope"))).click()
self.driver.find_element_by_css_selector(".header__nav-item.ng-scope").click()
# filling email field
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "password")))
self.driver.find_element_by_name("password").send_keys("159753")
WebDriverWait(self.driver, 10)
WebDriverWait(self.driver, 10)
self.driver.find_element_by_css_selector(".form-login__submit").click()
# check error message under form
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, "/html/body/main/div/div/div/form/div[2]/div/div")))
except TimeoutException:
print ("No such element in test_authorization_empty_email_field test")
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
Версии ОС и софта следующие …
Python 2.7