From 130107be65175322f1b4d178d3f340c62e0ff347 Mon Sep 17 00:00:00 2001 From: Nico Schedel Date: Wed, 18 Dec 2019 11:13:20 +0100 Subject: [PATCH] TT#70901 selenium: add file Functions.py this file will contain helper functions. first up is fill_element, which automatically replaces already filled in text, since send_keys wont do that. Change-Id: Ib815e403ba9d7fa808c57aecd09a464f45d21413 --- t/selenium/functions/Functions.py | 15 ++++++ t/selenium/testrun.py | 85 ++++++++----------------------- 2 files changed, 37 insertions(+), 63 deletions(-) create mode 100644 t/selenium/functions/Functions.py diff --git a/t/selenium/functions/Functions.py b/t/selenium/functions/Functions.py new file mode 100644 index 00000000..e6aeb275 --- /dev/null +++ b/t/selenium/functions/Functions.py @@ -0,0 +1,15 @@ +import os +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.action_chains import ActionChains +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.by import By +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities + + +def fill_element(driver, element, text, pathtype=By.XPATH): + elem = driver.find_element(pathtype, element) + elem.send_keys(Keys.CONTROL + "a") + elem.send_keys(Keys.DELETE) + elem.send_keys(text) diff --git a/t/selenium/testrun.py b/t/selenium/testrun.py index 5eae1fbb..ce4866b1 100644 --- a/t/selenium/testrun.py +++ b/t/selenium/testrun.py @@ -3,6 +3,7 @@ import os import nose2 import time import functions.Collections as Collections +import functions.Functions as Functions from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.desired_capabilities import DesiredCapabilities @@ -51,24 +52,12 @@ class testrun(unittest.TestCase): self.assertTrue(driver.find_element_by_xpath( '//div[contains(@class, "q-alert-container")]') .is_displayed(), "Error Message was not shown") - driver.find_element_by_xpath( - '//*[@id="csc-login-form"]//div//input[@type="text"]' - ).send_keys(Keys.CONTROL + "a") - driver.find_element_by_xpath( - '//*[@id="csc-login-form"]//div//input[@type="text"]' - ).send_keys(Keys.DELETE) - driver.find_element_by_xpath( - '//*[@id="csc-login-form"]//div//input[@type="text"]' - ).send_keys('testuser@' + domainname) - driver.find_element_by_xpath( - '//*[@id="csc-login-form"]//div//input[@type="password"]' - ).send_keys(Keys.CONTROL + "a") - driver.find_element_by_xpath( - '//*[@id="csc-login-form"]//div//input[@type="password"]' - ).send_keys(Keys.DELETE) - driver.find_element_by_xpath( - '//*[@id="csc-login-form"]//div//input[@type="password"]' - ).send_keys('testpasswd') + Functions.fill_element( + driver, '//*[@id="csc-login-form"]//div//input[@type=' + '"text"]', "testuser@" + domainname) + Functions.fill_element( + driver, '//*[@id="csc-login-form"]//div//input[@type=' + '"password"]', "testpasswd") driver.find_element_by_xpath( '//*[@id="csc-login"]//div//button').click() self.assertEqual("testuser", driver.find_element_by_xpath( @@ -241,15 +230,9 @@ class testrun(unittest.TestCase): driver.find_element_by_xpath( '//*[@id="q-app"]//div[contains(text(), "Destination")]/..' '/input').send_keys('testdestination') - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys(Keys.CONTROL + "a") - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys(Keys.DELETE) - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys("100") + Functions.fill_element( + driver, '//*[@id="q-app"]//div[contains(text(), "Timeout")]/' + '../input', "100") driver.find_element_by_xpath( '//*[@id="q-app"]//div[@class="add-destination-form"]//button' '/span[contains(text(), "Save")]').click() @@ -276,15 +259,9 @@ class testrun(unittest.TestCase): driver.find_element_by_xpath( '//*[@id="q-app"]//div[contains(text(), "Destination")]/..' '/input').send_keys('testdestination') - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys(Keys.CONTROL + "a") - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys(Keys.DELETE) - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys("200") + Functions.fill_element( + driver, '//*[@id="q-app"]//div[contains(text(), "Timeout")]/' + '../input', "200") driver.find_element_by_xpath( '//*[@id="q-app"]//div[@class="add-destination-form"]//button/' 'span[contains(text(), "Save")]').click() @@ -313,15 +290,9 @@ class testrun(unittest.TestCase): driver.find_element_by_xpath( '//*[@id="q-app"]//div[contains(text(), "Destination")]/..' '/input').send_keys('testdestination') - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys(Keys.CONTROL + "a") - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys(Keys.DELETE) - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Timeout")]/../' - 'input').send_keys("300") + Functions.fill_element( + driver, '//*[@id="q-app"]//div[contains(text(), "Timeout")]/' + '../input', "300") driver.find_element_by_xpath( '//*[@id="q-app"]//div[@class="add-destination-form"]//button/' 'span[contains(text(), "Save")]').click() @@ -625,15 +596,9 @@ class testrun(unittest.TestCase): driver.find_element_by_xpath( '//*[@id="q-app"]//div[contains(text(), "Change PIN")]/../../' 'i[1]').click() - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Change PIN")]/../' - 'input').send_keys(Keys.CONTROL + "a") - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Change PIN")]/../' - 'input').send_keys(Keys.DELETE) - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Change PIN")]/../' - 'input').send_keys("12345") + Functions.fill_element( + driver, '//*[@id="q-app"]//div[contains(text(), "Change PIN")]/../' + 'input', "12345") driver.find_element_by_xpath( '//*[@id="q-app"]//div[contains(text(), "Change PIN")]/../../' 'i[1]').click() @@ -646,15 +611,9 @@ class testrun(unittest.TestCase): driver.find_element_by_xpath( '//*[@id="q-app"]//div[contains(text(), "Change Email")]/../../' 'i[1]').click() - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Change Email")]/../' - 'input').send_keys(Keys.CONTROL + "a") - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Change Email")]/../' - 'input').send_keys(Keys.DELETE) - driver.find_element_by_xpath( - '//*[@id="q-app"]//div[contains(text(), "Change Email")]/../' - 'input').send_keys("test@email.com") + Functions.fill_element( + driver, '//*[@id="q-app"]//div[contains(text(), "Change Email")]' + '/../input', "test@email.com") driver.find_element_by_xpath( '//*[@id="q-app"]//div[contains(text(), "Change Email")]/../../' 'i[1]').click()