-
Notifications
You must be signed in to change notification settings - Fork 0
add the 1st selenium examples. SUT will be done later #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?xml version="1.0"?> | ||
| <sitemodel> | ||
| <pages> | ||
| <page name="LoginPage"> | ||
| <element Key="LoginUserName"> | ||
| <searchby>Id</searchby> | ||
| <value>login_login_username</value> | ||
| </element> | ||
| </page> | ||
| <page name="LoginPage"> | ||
| <element Key="LoginPassword"> | ||
| <searchby>Id</searchby> | ||
| <value>login_login_password</value> | ||
| </element> | ||
| </page> | ||
| <page name = "LoginPage"> | ||
| <element Key="SubmitButton"> | ||
| <searchby>Id</searchby> | ||
| <value>login_submit</value> | ||
| </element> | ||
| </page> | ||
| <page name="DashboardPage"><element Key="LogoutLink"> | ||
| <searchby>LinkText</searchby> | ||
| <value>Logout</value> | ||
| </element></page> | ||
| <page name="DashboardPage"><element Key="Mahara"> | ||
| <searchby>LinkText</searchby> | ||
| <value>Mahara</value> | ||
| </element></page> | ||
| </pages> | ||
|
|
||
| </sitemodel> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import unittest | ||
| import time | ||
| import sys | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.support.ui import WebDriverWait | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
|
|
||
|
|
||
| class ePO_login(unittest.TestCase): | ||
|
|
||
| """ | ||
| This sample exercise the explicit wait function | ||
| The ExpectedConditions are listed below: | ||
| prerequsite: my_email and password must be registered at manage.mcafee.com | ||
|
|
||
| title_is | ||
| title_contains | ||
| presence_of_element_located | ||
| visibility_of_element_located | ||
| visibility_of | ||
| presence_of_all_elements_located | ||
| text_to_be_present_in_element | ||
| text_to_be_present_in_element_value | ||
| frame_to_be_available_and_switch_to_it | ||
| invisibility_of_element_located | ||
| element_to_be_clickable - it is Displayed and Enabled. | ||
| staleness_of | ||
| element_to_be_selected | ||
| element_located_to_be_selected | ||
| element_selection_state_to_be | ||
| element_located_selection_state_to_be | ||
| alert_is_present | ||
| """ | ||
|
|
||
| def setUp(self): | ||
| self.driver = webdriver.Firefox() | ||
|
|
||
| def test_login(self): | ||
| driver = self.driver | ||
| driver.get("http://manage.mcafee.com") | ||
| assert "Log On" in driver.title | ||
| elem = driver.find_element_by_id('logOnEmailAddress') | ||
| elem.clear() | ||
| elem.send_keys('my@email.com') | ||
| elem = driver.find_element_by_id('logOnPassword') | ||
| elem.clear() | ||
| elem.send_keys('password') | ||
| elem = driver.find_element_by_id('logOnButton') | ||
| elem.click() | ||
| # time.sleep(10) # implicit wait | ||
| # explicit wait EC.presence_of_element | ||
| try: | ||
| element = WebDriverWait(driver, 20).until( | ||
| EC.presence_of_element_located((By.ID, "mfaTitle")) | ||
| ) | ||
| except IOError as e: | ||
| print("I/O errors({0}): {1}".format(e.errorno, e.strerror)) | ||
| except ValueError: | ||
| print("Value Error") | ||
| except: | ||
| print("Unexpected error (can't find the control)") | ||
| finally: | ||
| pass | ||
|
|
||
| elem = driver.find_element_by_xpath("//*[text()='Dashboards']") | ||
| elem.click() | ||
| # explicit wait EC.text_to_be_present | ||
| try: | ||
| element = WebDriverWait(driver, 10).until( | ||
| EC.text_to_be_present_in_element_value | ||
| ((By.ID, "mfaTitle"), 'Dashboards') | ||
| ) | ||
| except IOError as e: | ||
| print("I/O errors({0}): {1}".format(e.errorno, e.strerror)) | ||
| except ValueError: | ||
| print("Value Error") | ||
| except: | ||
| print("Unexpected error (can't find the control)") | ||
| finally: | ||
| pass | ||
|
|
||
| elem = driver.find_element_by_xpath("//*[text()='Getting Started']") | ||
| elem.click() | ||
| elem = driver.find_element_by_xpath("//*[text()='Systems']") | ||
| elem.click() | ||
| elem = driver.find_element_by_xpath("//*[text()='Queries & Reports']") | ||
| elem.click() | ||
|
|
||
| assert "ePolicy" in driver.title | ||
|
|
||
| def tearDown(self): | ||
| self.driver.close() | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
|
|
||
| __author__ = 'mpsauto' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import unittest | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.support.ui import WebDriverWait | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
|
|
||
|
|
||
| class PythonOrgSearch(unittest.TestCase): | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ''' | ||
| Learning point 1: Combination of Unittest framework with the selenium | ||
| Learning point 2: Web page navigation: driver.get(), forward(), back() | ||
| Learning point 3: Find element(s): id,name,xpath,class_name,link,tag,css | ||
| Learning point 3: Web interaction: click, send_keys, | ||
| Learning point 4: todo: select from drop-down options | ||
| Learning point 5: todo: drag-and-drop, | ||
| Learning point 6: todo: switch between windows and frames (iframe) | ||
| Learning point 7: todo: handling popup dialog | ||
| Learning point 8: todo: explicit wait (conditions) and implicit wait | ||
| Learning point 9: todo: execution sequence | ||
| Learning point10: todo: PageObjectModel (see python_org.py codes) | ||
| ''' | ||
|
|
||
| def setUp(self): | ||
| self.driver = webdriver.Firefox() | ||
|
|
||
| def test_search_in_python_org(self): | ||
| driver = self.driver | ||
| driver.get("http://www.google.com") | ||
| assert "Google" in driver.title | ||
| elem = driver.find_element_by_name('q') | ||
| elem.clear() | ||
| elem.send_keys("pycon") | ||
| elem.send_keys(Keys.RETURN) | ||
| assert "No results found." not in driver.page_source | ||
|
|
||
| def test_explicit_wait(self): | ||
| driver = self.driver | ||
| driver.get("http://somedomain/url_that_delays_loading") | ||
| element = WebDriverWait(driver, 10).until( | ||
| EC.presence_of_element_located((By.ID, "myDynamicElement"))) | ||
|
|
||
| def test_implicit_wait(self): | ||
| driver = self.driver | ||
| driver.implicitly_wait(10) # sec | ||
| driver.get("http://somedomain/url_that_delays_loading") | ||
| myDynamicElement = driver.find_element_by_id("myDynamicElement") | ||
|
|
||
| def tearDown(self): | ||
| self.driver.close() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import unittest | ||
| import xml.etree.ElementTree as ET | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.keys import Keys | ||
|
|
||
| tree = ET.parse('SiteElement.xml') | ||
| root = tree.getroot() | ||
|
|
||
| def getSearchValue(pagenameattribute, elementkeystring): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix pep8 error for this file |
||
| xpathstring = "./pages/page[@name='" + \ | ||
| pagenameattribute+"']/element[@Key='" + \ | ||
| elementkeystring+"']" | ||
| print(xpathstring) | ||
| for element in root.findall(xpathstring): | ||
| value = element.find('value').text | ||
| return value | ||
|
|
||
| def getSearchBy(pagenameattribute, elementkeystring): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| xpathstring = "./page/page[@name='" + \ | ||
| pagenameattribute+"']/element[@Key='" + \ | ||
| elementkeystring + "']" | ||
| print(xpathstring) | ||
| for element in root.findall('searchby').text: | ||
| searchby = element.find('searchby') | ||
| return searchby | ||
|
|
||
|
|
||
| class DemoMaharaOrgLogin(unittest.TestCase): | ||
| ''' | ||
| Learning Point: The page struc is described in SiteElement.xml | ||
| ''' | ||
| def setUp(self): | ||
| self.driver = webdriver.Firefox() | ||
|
|
||
| def test_login_in_demo_mahara_org(self): | ||
| driver = self.driver | ||
| driver.get("http://demo.mahara.org/") | ||
| self.assertIn("Home - Mahara", driver.title) | ||
|
|
||
| username = driver.find_element_by_id(getSearchValue | ||
| ("LoginPage", "LoginUserName")) | ||
| username.send_keys(("student1")) | ||
|
|
||
| password = driver.find_element_by_id( | ||
| getSearchValue("LoginPage", "LoginPassword")) | ||
| password.send_keys("Testing1") | ||
|
|
||
| loginbutton = driver.find_element_by_id(getSearchValue | ||
| ("LoginPage", "SubmitButton")) | ||
| loginbutton.click() | ||
|
|
||
| self.assertTrue(driver.find_element_by_link_text( | ||
| getSearchValue("DashboardPage", "LogoutLink")), "Logout link") | ||
|
|
||
| def tearDown(self): | ||
| self.driver.close() | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| from selenium import webdriver | ||
| from page_objects import PageObject, PageElement | ||
|
|
||
|
|
||
| class LoginPage(PageObject): | ||
| ''' | ||
| Page Object Model sample code package (page_objects) | ||
| https://page-objects.readthedocs.io/en/latest/tutorial.html | ||
| https://media.readthedocs.org/pdf/page-objects/latest/page-objects.pdf | ||
|
|
||
| <html> | ||
| <head> | ||
| <title>Login Page</title> | ||
| </head> | ||
| <body> | ||
| <form type="POST" action="/login"> | ||
| <input type="text" name="username" id="user-input"></input> | ||
| <input type="password" name="password"></input> | ||
| <input type="submit">Submit</input> | ||
| </form> | ||
| </body> | ||
| </html> | ||
| ''' | ||
| username = PageElement(id_='user-input') | ||
| password = PageElement(name='password') | ||
| login = PageElement(css='input[type="submit"]') | ||
| form = PageElement(tag_name='form') | ||
|
|
||
|
|
||
| driver = webdriver.PhantomJS() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is phantomjs? any traps for installation on Linux 64, Mac, and Windows? |
||
| driver.get("http://example.com") | ||
| page = LoginPage(driver) | ||
| page.username = 'secret' | ||
| page.password = 'squirrel' | ||
| assert page.username.text == 'secret' | ||
| page.login.click() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed test