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
changes/92/36292/2
Nico Schedel 6 years ago
parent e77e735186
commit 130107be65

@ -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)

@ -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()

Loading…
Cancel
Save