├── CODES ├── S10 - Modules │ ├── 1-modules-demo1.py │ ├── 2-car.py │ └── 2-modules-demo2.py ├── S11 - Working With Files │ ├── 1-filedemo1.py │ ├── 2-filedemo2.py │ ├── 2-firstfile.txt │ ├── 3-withasdemo.py │ └── Thumbs.db ├── S12 - How To Inspect Elements Different Browsers - Add-Ons │ ├── 7-notes.txt │ └── Thumbs.db ├── S13 - Selenium WebDriver -_ Setup And Installation │ ├── 3 - Selenium 3 Requirements.pdf │ ├── 4 - Selenium WebDriver 3.x GeckoDriver Path - Mac.pdf │ ├── 4 - Selenium WebDriver 3.x GeckoDriver Path - Windows.pdf │ └── Thumbs.db ├── S14 - Selenium WebDriver -_ Running Tests On Various Browsers │ ├── 1-RunFFTests.py │ ├── 2-RunChromeTests.py │ ├── 3-RunChromeTestsWindows.py │ ├── 5-RunIETestsWindows.py │ ├── 6 - Requirements To Run Tests On Safari.pdf │ ├── 6-Requirements to Run Tests on Safari.pdf │ ├── 7-RunSafariTests.py │ ├── 8-How To Set Drivers In System Path - Mac.pdf │ ├── 8-Interview Questions.pdf │ ├── 9-How To Set Drivers In System Path - Windows.pdf │ └── Thumbs.db ├── S15 - Selenium WebDriver -_ Finding Elements │ ├── 1-Find Elements.pdf │ ├── 2-FindByIdName.py │ ├── 3-FindByIdName.py │ ├── 4-FindByXPathCSS.py │ ├── 5-FindByLinkText.py │ ├── 6-FindByClassTag.py │ ├── 7-ByDemo.py │ ├── 8-ListOfElements.py │ ├── 9-Interview Questions.pdf │ └── Thumbs.db ├── S16 - CSS Selectors - Advanced Locators │ ├── 5 - CSS Selectors Cheat Sheet.pdf │ └── Thumbs.db ├── S17 - Xpath - Advanced Locators │ ├── 1-XPath Cheat Sheet.pdf │ ├── 2-XPath Cheat Sheet.pdf │ ├── 3-XPath Cheat Sheet.pdf │ ├── 4-XPath Cheat Sheet.pdf │ ├── 5-XPath Cheat Sheet.pdf │ ├── 6 XPath Cheat Sheet.pdf │ ├── 7-XPath Cheat Sheet.pdf │ ├── 8 - XPath Cheat Sheet.pdf │ └── Thumbs.db ├── S18 - Selenium WebDriver -_ Working With Web Elements │ ├── 1-Browser Interaction And Navigating Web Pages.pdf │ ├── 10-HiddenElements.py │ ├── 11-Interview Questions.pdf │ ├── 2-BrowserInteractions.py │ ├── 3-ClickAndSendKeys.py │ ├── 4-ElementState.py │ ├── 5-RadioButtonsAndCheckboxes.py │ ├── 6-WorkingWithElementsList.py │ ├── 8-DropdownSelect.py │ └── Thumbs.db ├── S2 - Setup And Configuration │ ├── 5-Python-Mac-Setup.pdf │ └── Thumbs.db ├── S20 - Selenium WebDriver -_ Useful Methods And Properties │ ├── 1_getText.py │ ├── 2_getAttribute.py │ ├── 3_handy-wrappers.py │ ├── 4_element-present-check.py │ ├── 4_handy-wrappers.py │ ├── 5_dynamic-xpath-format.py │ ├── 6-Interview Questions.docx │ ├── 6-Interview Questions.pdf │ └── Thumbs.db ├── S21 - Selenium WebDriver -_ Wait Types │ ├── 1-Wait Types.pdf │ ├── 2-implicit-wait-demo.py │ ├── 3-explicit-wait-demo1.py │ ├── 4-explicit-wait-demo2.py │ ├── 4-explicit-wait-type.py │ ├── 4-handy-wrappers.py │ ├── 5-Interview Questions.pdf │ └── Thumbs.db ├── S22 - Selenium WebDriver -_ Advanced │ ├── 10_scrolling-element.py │ ├── 11-Interview Questions.pdf │ ├── 2_calendar-selection.py │ ├── 3_calendar-selection.py │ ├── 5_auto-complete.py │ ├── 6_screenshots.py │ ├── 7_screenshots-generic.py │ ├── 8_javascript-execution.py │ ├── 9_window-size.py │ └── Thumbs.db ├── S23 - Selenium WebDriver -_ Switch Window And IFrames │ ├── 1_switch-to-window.py │ ├── 2_switch-to-window.py │ ├── 3_switch-to-frame.py │ ├── 4_switch-to-frame.py │ ├── 5_switch-to-alert.py │ └── Thumbs.db ├── S24 - Selenium WebDriver -_ Working With Actions Class │ ├── 1-mouse-hovering.py │ ├── 2-drag-and-drop.py │ ├── 3-sliders.py │ └── Thumbs.db ├── S25 - Logging Infrastructure │ └── Please Read.txt ├── S26 - Unittest Infrastructure │ ├── 26.jpg │ ├── 5 - How to set project directory path - Windows.pdf │ ├── Please Read.txt │ └── Thumbs.db ├── S27 - Pytest -_ Advanced Testing Framework │ ├── 1-test-case-demo1.py │ ├── 10 - Installing PyTest HTML Plugin.docx │ ├── 10 - Installing PyTest HTML Plugin.pdf │ ├── 11-class-to-test.py │ ├── 11-conftest.py │ ├── 11-test-reporting-demo.py │ ├── 2 - PyTest Naming Conventions.docx │ ├── 2 - PyTest Naming Conventions.pdf │ ├── 2 - PyTest Naming Conventions_page-0001.jpg │ ├── 3-test-case-demo2.py │ ├── 4-test-case-demo1.py │ ├── 4-test-case-demo2.py │ ├── 4-test-case-demo3.py │ ├── 5-conftest.py │ ├── 5-test-conftest-demo1.py │ ├── 5-test-conftest-demo2.py │ ├── 6-conftest.py │ ├── 6-test-run-order-demo.py │ ├── 7-conftest.py │ ├── 7-test-command-line-args.py │ ├── 8-class-to-test.py │ ├── 8-conftest.py │ ├── 8-test-class-demo1.py │ ├── 9-class-to-test.py │ ├── 9-conftest.py │ ├── 9-test-class-demo2.py │ └── Thumbs.db ├── S28 - Automation Framework - Part 1 │ ├── 3_login_tests.py │ ├── 4_login_page.py │ ├── 4_login_tests.py │ ├── 5_login_page.py │ ├── 6_selenium_driver.py │ ├── 7_login_page.py │ ├── 7_login_tests.py │ ├── 7_selenium_driver.py │ └── Thumbs.db ├── S29 - Automation Framework - Part 2 │ ├── 1_custom_logger.py │ ├── 1_login_page.py │ ├── 1_login_tests.py │ ├── 1_selenium_driver.py │ ├── 2_login_page.py │ ├── 2_login_tests.py │ ├── 2_selenium_driver.py │ ├── 3_login_page.py │ ├── 3_login_tests.py │ ├── 3_selenium_driver.py │ ├── 4_conftest.py │ ├── 4_login_page.py │ ├── 4_login_tests.py │ ├── 4_selenium_driver.py │ ├── 5_conftest.py │ ├── 5_login_page.py │ ├── 5_login_tests.py │ ├── 5_selenium_driver.py │ ├── 5_webdriverfactory.py │ └── Thumbs.db ├── S3 - Understanding Variables And Data Type │ ├── 10-string-methods2.py │ ├── 12-strings-formatting.py │ ├── 2-variables.py │ ├── 3-Variables Rules.docx │ ├── 3-Variables Rules.pdf │ ├── 3-variables-rules.py │ ├── 4-numbers.py │ ├── 5-numbers-operations.py │ ├── 7-boolean.py │ ├── 8-strings.py │ ├── 9-string-methods1.py │ └── Thumbs.db ├── S30 - Automation Framework - Part 3 │ ├── 1_login_page.py │ ├── 1_login_tests.py │ ├── 1_selenium_driver.py │ ├── 2_teststatus.py │ ├── 3_login_tests.py │ ├── 3_teststatus.py │ ├── 4_selenium_driver.py │ ├── 5_selenium_driver.py │ ├── 5_teststatus.py │ ├── 6_basepage.py │ ├── 6_util.py │ ├── 7_basepage.py │ ├── 7_login_page.py │ ├── 7_login_tests.py │ ├── 7_util.py │ └── Thumbs.db ├── S31 - Automation Framework -_ Practice Exercise │ ├── 1_conftest.py │ ├── 1_selenium_driver.py │ ├── 3_register_courses_pages.py │ ├── 4_register_courses_pages.py │ ├── 5_register_courses_page.py │ ├── 5_register_courses_tests.py │ ├── 6_register_courses_page.py │ ├── 6_register_courses_tests.py │ ├── 6_selenium_driver.py │ ├── 7_register_courses_page.py │ ├── 7_register_courses_tests.py │ ├── 7_selenium_driver.py │ └── Thumbs.db ├── S32 - Data Driven Testing │ ├── 2_register_courses_multiple_data_set.py │ ├── 3_read_data.py │ ├── 4-testdata.csv │ ├── 4_read_data.py │ ├── 4_register_courses_csv_data.py │ └── Thumbs.db ├── S33 - Running Complete Test Suite │ ├── 1_navigation_page.py │ ├── 1_register_courses_csv_data.py │ ├── 2_login_page.py │ ├── 2_login_tests.py │ ├── 3_test_suite_demo.py │ ├── 4_login_page.py │ ├── 4_navigation_page.py │ ├── 4_webdriverfactory.py │ └── Thumbs.db ├── S4 - Advanced Data Types │ ├── 1-listdemo.py │ ├── 2-listmethods.py │ ├── 3-dictdemo.py │ ├── 4-dictnested.py │ ├── 5-dictmethods.py │ ├── 6-tuplesdemo.py │ └── Thumbs.db ├── S5 - Comparison And Boolean Operators │ ├── 1-comparators.py │ ├── 1_navigation_page.py │ ├── 1_register_courses_csv_data.py │ ├── 2-boolean-operators.py │ ├── 2_login_page.py │ ├── 2_login_tests.py │ ├── 2_register_courses_multiple_data_set.py │ ├── 3-boolean-precedence.py │ ├── 3_read_data.py │ ├── 3_test_suite_demo.py │ ├── 4-testdata.csv │ ├── 4_login_page.py │ ├── 4_navigation_page.py │ ├── 4_read_data.py │ ├── 4_register_courses_csv_data.py │ └── 4_webdriverfactory.py ├── S6 - Program Control Flow │ ├── 1-conditional.py │ ├── 2-whiledemo.py │ ├── 3-breakcontinue.py │ ├── 4-forloopdemo.py │ ├── 5-multiplelist.py │ └── 6-rangedemo.py ├── S7 - Functions-Methods - Working With Reusable Code │ ├── 1-methodsdemo1.py │ ├── 2-methodsdemo2.py │ ├── 3-methodsdemo3.py │ ├── 4-methodsdemo4.py │ ├── 5-built-in-functions.py │ ├── 6-Method-Exercise.pdf │ └── 6-methodexercise.py ├── S8 - Classes - Object Oriented Programming │ ├── 1-classdemo1.py │ ├── 2-classdemo2.py │ ├── 3-classdemo3.py │ ├── 4-classdemo-inheritance1.py │ ├── 5-classdemo-inheritance2.py │ ├── 6-Class-Exercise.pdf │ └── 6-classexercise.py └── S9 - Exception Handling │ ├── 1-exceptionhandling1.py │ └── 2-exceptionhandling2.py ├── LICENSE └── README.md /CODES/S10 - Modules/1-modules-demo1.py: -------------------------------------------------------------------------------- 1 | """ 2 | https://docs.python.org/3/library/ 3 | """ 4 | import math 5 | from math import sqrt 6 | 7 | class ModulesDemo(): 8 | 9 | def builtin_modules(self): 10 | print(math.sqrt(100)) 11 | print(sqrt(100)) 12 | 13 | 14 | m = ModulesDemo() 15 | m.builtin_modules() -------------------------------------------------------------------------------- /CODES/S10 - Modules/2-car.py: -------------------------------------------------------------------------------- 1 | """ 2 | This is our own module which does not exist in python builtins 3 | """ 4 | 5 | def info(make, model): 6 | print("Make of the car: " + make) 7 | print("Model of the car: " + model) -------------------------------------------------------------------------------- /CODES/S10 - Modules/2-modules-demo2.py: -------------------------------------------------------------------------------- 1 | """ 2 | https://docs.python.org/3/library/ 3 | """ 4 | import math 5 | from math import sqrt 6 | from modulesexternal.car import info 7 | 8 | class ModulesDemo(): 9 | 10 | def builtin_modules(self): 11 | print(math.sqrt(100)) 12 | print(sqrt(100)) 13 | 14 | def car_description(self): 15 | make = "bmw" 16 | model = "550i" 17 | info(make, model) 18 | 19 | 20 | m = ModulesDemo() 21 | m.builtin_modules() 22 | m.car_description() -------------------------------------------------------------------------------- /CODES/S11 - Working With Files/1-filedemo1.py: -------------------------------------------------------------------------------- 1 | """ 2 | File I/O 3 | 'w' -> Write-Only Mode 4 | 'r' -> Read-only Mode 5 | 'r+' -> Read And Write Mode 6 | 'a' -> Append Mode 7 | """ 8 | 9 | my_list = [1, 2, 3] 10 | 11 | my_file = open("firstfile.txt", "w") 12 | 13 | for item in my_list: 14 | my_file.write(str(item) + "\n") 15 | 16 | my_file.close() -------------------------------------------------------------------------------- /CODES/S11 - Working With Files/2-filedemo2.py: -------------------------------------------------------------------------------- 1 | """ 2 | File I/O 3 | Reading a file -> .read() 4 | Reading line by line -> .readline() 5 | """ 6 | 7 | my_file = open("firstfile.txt", 'r') 8 | 9 | print(str(my_file.read())) 10 | my_file.close() 11 | 12 | print("Line by line ========>>") 13 | 14 | my_file_line = open("firstfile.txt", 'r') 15 | print(str(my_file_line.readline())) 16 | print(str(my_file_line.readline())) 17 | print(str(my_file_line.readline())) 18 | 19 | my_file_line.close() -------------------------------------------------------------------------------- /CODES/S11 - Working With Files/2-firstfile.txt: -------------------------------------------------------------------------------- 1 | first line 2 | second line 3 | third line -------------------------------------------------------------------------------- /CODES/S11 - Working With Files/3-withasdemo.py: -------------------------------------------------------------------------------- 1 | """ 2 | With / As Keywords 3 | """ 4 | # print("Normal Write Start") 5 | # my_write = open("textfile.txt", "w") 6 | # my_write.write("Trying to write to the file") 7 | # my_write.close() 8 | # 9 | # 10 | # print("Normal Read Start") 11 | # my_read = open("textfile.txt", "r") 12 | # print(str(my_read.read())) 13 | 14 | print("With As Write Start") 15 | with open("withas.txt", "w") as with_as_write: 16 | with_as_write.write("This is an example of with as write/read") 17 | 18 | print() 19 | print("With As Read Start") 20 | with open("withas.txt", "r") as with_as_read: 21 | print(str(with_as_read.read())) -------------------------------------------------------------------------------- /CODES/S11 - Working With Files/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S11 - Working With Files/Thumbs.db -------------------------------------------------------------------------------- /CODES/S12 - How To Inspect Elements Different Browsers - Add-Ons/7-notes.txt: -------------------------------------------------------------------------------- 1 | Firefox: 2 | 3 | XPath -> //input[@id=‘name’] 4 | CSS -> #name 5 | 6 | Chrome: 7 | 8 | XPath -> //input[@id=‘name’] 9 | CSS -> #name 10 | 11 | Ranorex Selocity: 12 | 13 | Xpath -> //input[@id='name'] 14 | CSS -> #name -------------------------------------------------------------------------------- /CODES/S12 - How To Inspect Elements Different Browsers - Add-Ons/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S12 - How To Inspect Elements Different Browsers - Add-Ons/Thumbs.db -------------------------------------------------------------------------------- /CODES/S13 - Selenium WebDriver -_ Setup And Installation/3 - Selenium 3 Requirements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S13 - Selenium WebDriver -_ Setup And Installation/3 - Selenium 3 Requirements.pdf -------------------------------------------------------------------------------- /CODES/S13 - Selenium WebDriver -_ Setup And Installation/4 - Selenium WebDriver 3.x GeckoDriver Path - Mac.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S13 - Selenium WebDriver -_ Setup And Installation/4 - Selenium WebDriver 3.x GeckoDriver Path - Mac.pdf -------------------------------------------------------------------------------- /CODES/S13 - Selenium WebDriver -_ Setup And Installation/4 - Selenium WebDriver 3.x GeckoDriver Path - Windows.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S13 - Selenium WebDriver -_ Setup And Installation/4 - Selenium WebDriver 3.x GeckoDriver Path - Windows.pdf -------------------------------------------------------------------------------- /CODES/S13 - Selenium WebDriver -_ Setup And Installation/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S13 - Selenium WebDriver -_ Setup And Installation/Thumbs.db -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/1-RunFFTests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | class RunFFTests(): 4 | 5 | def testMethod(self): 6 | # Initiate the driver instance 7 | driver = webdriver.Firefox( 8 | executable_path="/Users/atomar/Documents/workspace_personal/libs/geckodriver") 9 | 10 | # Windows 11 | # driver = webdriver.Firefox(executable_path="D:\\location\\geckodriver.exe") 12 | driver.get("http://www.letskodeit.com") 13 | 14 | ff = RunFFTests() 15 | ff.testMethod() -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/2-RunChromeTests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import os 3 | 4 | class RunChromeTests(): 5 | # http://chromedriver.storage.googleapis.com/index.html 6 | 7 | def test(self): 8 | driverLocation = "/Users/atomar/Documents/workspace_personal/selenium/chromedriver" 9 | os.environ["webdriver.chrome.driver"] = driverLocation 10 | # Instantiate Chrome Browser Command 11 | driver = webdriver.Chrome(driverLocation) 12 | # Open the provided URL 13 | driver.get("http://www.letskodeit.com") 14 | 15 | ff = RunChromeTests() 16 | ff.test() -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/3-RunChromeTestsWindows.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import os 3 | 4 | class RunChromeTestsWindows(): 5 | # https://sites.google.com/a/chromium.org/chromedriver/downloads 6 | # http://chromedriver.storage.googleapis.com/index.html?path=2.21/ 7 | def test(self): 8 | driverLocation = "C:\\Users\\Anil Tomar\\PycharmProjects\\libs\\chromedriver.exe" 9 | os.environ["webdriver.chrome.driver"] = driverLocation 10 | driver = webdriver.Chrome(driverLocation) 11 | driver.get("http://www.letskodeit.com") 12 | 13 | chromeTest = RunChromeTestsWindows() 14 | chromeTest.test() -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/5-RunIETestsWindows.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import os 3 | 4 | class RunIETestsWindows(): 5 | 6 | def test(self): 7 | driverLocation = "C:\\Users\\Anil Tomar\\PycharmProjects\\libs\\IEDriverServer.exe" 8 | os.environ["webdriver.ie.driver"] = driverLocation 9 | driver = webdriver.Ie(driverLocation) 10 | driver.get("http://www.letskodeit.com") 11 | 12 | ieTest = RunIETestsWindows() 13 | ieTest.test() -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/6 - Requirements To Run Tests On Safari.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/6 - Requirements To Run Tests On Safari.pdf -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/6-Requirements to Run Tests on Safari.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/6-Requirements to Run Tests on Safari.pdf -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/7-RunSafariTests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import os 3 | 4 | class RunSafariTests(): 5 | # https://github.com/SeleniumHQ/selenium/wiki/SafariDriver 6 | # http://selenium-release.storage.googleapis.com/index.html 7 | 8 | def test(self): 9 | serverLocation = "/Users/atomar/Documents/workspace_personal/selenium/selenium-server-standalone-2.53.0.jar" 10 | os.environ["SELENIUM_SERVER_JAR"] = serverLocation 11 | # Instantiate Safari Browser Command 12 | driver = webdriver.Safari(quiet=True) 13 | # Open the provided URL 14 | driver.get("http://www.letskodeit.com") 15 | 16 | safari = RunSafariTests() 17 | safari.test() -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/8-How To Set Drivers In System Path - Mac.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/8-How To Set Drivers In System Path - Mac.pdf -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/8-Interview Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/8-Interview Questions.pdf -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/9-How To Set Drivers In System Path - Windows.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/9-How To Set Drivers In System Path - Windows.pdf -------------------------------------------------------------------------------- /CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S14 - Selenium WebDriver -_ Running Tests On Various Browsers/Thumbs.db -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/1-Find Elements.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S15 - Selenium WebDriver -_ Finding Elements/1-Find Elements.pdf -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/2-FindByIdName.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | class FindByIdName(): 4 | 5 | def test(self): 6 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 7 | driver = webdriver.Firefox() 8 | driver.get(baseUrl) 9 | elementById = driver.find_element_by_id("name") 10 | 11 | if elementById is not None: 12 | print("We found an element by Id") 13 | 14 | elementByName = driver.find_element_by_name("show-hide") 15 | 16 | if elementByName is not None: 17 | print("We found an element by Name") 18 | 19 | ff = FindByIdName() 20 | ff.test() -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/3-FindByIdName.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | class FindByIdName(): 4 | 5 | def test(self): 6 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 7 | driver = webdriver.Firefox() 8 | driver.get(baseUrl) 9 | elementById = driver.find_element_by_id("name") 10 | 11 | if elementById is not None: 12 | print("We found an element by Id") 13 | 14 | elementByName = driver.find_element_by_name("show-hide") 15 | 16 | if elementByName is not None: 17 | print("We found an element by Name") 18 | 19 | driver.get("https://www.yahoo.com/") 20 | # This one should fail because the Id is not static 21 | # Exception thrown: NoSuchElementException 22 | driver.find_element_by_id("yui_3_18_0_4_1463100170626_1148") 23 | 24 | ff = FindByIdName() 25 | ff.test() -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/4-FindByXPathCSS.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | class FindByXPathCSS(): 4 | 5 | def test(self): 6 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 7 | driver = webdriver.Firefox() 8 | driver.get(baseUrl) 9 | elementByXpath = driver.find_element_by_xpath("//input[@id='name']") 10 | 11 | if elementByXpath is not None: 12 | print("We found an element by XPATH") 13 | 14 | elementByCss = driver.find_element_by_css_selector("#displayed-text") 15 | 16 | if elementByCss is not None: 17 | print("We found an element by CSS") 18 | 19 | ff = FindByXPathCSS() 20 | ff.test() -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/5-FindByLinkText.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | 4 | class FindByLinkText(): 5 | 6 | def test(self): 7 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 8 | driver = webdriver.Firefox() 9 | driver.get(baseUrl) 10 | 11 | elementByLinkText = driver.find_element_by_link_text("Login") 12 | 13 | if elementByLinkText is not None: 14 | print("We found an element by Link Text") 15 | 16 | elementByPartialLinkText = driver.find_element_by_partial_link_text("Pract") 17 | 18 | if elementByPartialLinkText is not None: 19 | print("We found an element by Partial Link Text") 20 | 21 | ff = FindByLinkText() 22 | ff.test() -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/6-FindByClassTag.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | class FindByClassTag(): 4 | 5 | def test(self): 6 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 7 | driver = webdriver.Firefox() 8 | driver.get(baseUrl) 9 | 10 | elementByClassName = driver.find_element_by_class_name("displayed-class") 11 | elementByClassName.send_keys("Testing The Element") 12 | 13 | if elementByClassName is not None: 14 | print("We found an element by Class Name") 15 | 16 | elementByTagName = driver.find_element_by_tag_name("h1") 17 | text = elementByTagName.text 18 | 19 | if elementByTagName is not None: 20 | print("We found an element by Tag Name and the text on element is: " + text) 21 | 22 | ff = FindByClassTag() 23 | ff.test() -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/7-ByDemo.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | 4 | class ByDemo(): 5 | 6 | def test(self): 7 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 8 | driver = webdriver.Firefox() 9 | driver.get(baseUrl) 10 | 11 | elementById = driver.find_element(By.ID, "name") 12 | 13 | if elementById is not None: 14 | print("We found an element by Id") 15 | 16 | elementByXpath = driver.find_element(By.XPATH, "//input[@id='displayed-text']") 17 | 18 | if elementByXpath is not None: 19 | print("We found an element by XPATH") 20 | 21 | elementByLinkText = driver.find_element(By.LINK_TEXT, "Login") 22 | 23 | if elementByLinkText is not None: 24 | print("We found an element by Link Text") 25 | 26 | ff = ByDemo() 27 | ff.test() -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/8-ListOfElements.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | 4 | class ListOfElements(): 5 | 6 | def test(self): 7 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 8 | driver = webdriver.Firefox() 9 | driver.get(baseUrl) 10 | 11 | elementListByClassName = driver.find_elements_by_class_name("inputs") 12 | length1 = len(elementListByClassName) 13 | 14 | if elementListByClassName is not None: 15 | print("ClassName -> Size of the list is: " + str(length1)) 16 | 17 | elementListByTagName = driver.find_elements(By.TAG_NAME, "td") 18 | length2 = len(elementListByTagName) 19 | 20 | if elementListByTagName is not None: 21 | print("TagName -> Size of the list is: " + str(length2)) 22 | 23 | ff = ListOfElements() 24 | ff.test() -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/9-Interview Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S15 - Selenium WebDriver -_ Finding Elements/9-Interview Questions.pdf -------------------------------------------------------------------------------- /CODES/S15 - Selenium WebDriver -_ Finding Elements/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S15 - Selenium WebDriver -_ Finding Elements/Thumbs.db -------------------------------------------------------------------------------- /CODES/S16 - CSS Selectors - Advanced Locators/5 - CSS Selectors Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S16 - CSS Selectors - Advanced Locators/5 - CSS Selectors Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S16 - CSS Selectors - Advanced Locators/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S16 - CSS Selectors - Advanced Locators/Thumbs.db -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/1-XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/1-XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/2-XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/2-XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/3-XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/3-XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/4-XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/4-XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/5-XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/5-XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/6 XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/6 XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/7-XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/7-XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/8 - XPath Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/8 - XPath Cheat Sheet.pdf -------------------------------------------------------------------------------- /CODES/S17 - Xpath - Advanced Locators/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S17 - Xpath - Advanced Locators/Thumbs.db -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/1-Browser Interaction And Navigating Web Pages.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S18 - Selenium WebDriver -_ Working With Web Elements/1-Browser Interaction And Navigating Web Pages.pdf -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/10-HiddenElements.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import time 3 | 4 | class HiddenElements(): 5 | 6 | def testLetsKodeIt(self): 7 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | driver.get(baseUrl) 11 | driver.implicitly_wait(2) 12 | 13 | 14 | # Find the state of the text box 15 | textBoxElement = driver.find_element_by_id("displayed-text") 16 | textBoxState = textBoxElement.is_displayed() # True if visible, False if hidden 17 | # Exception if not present in the DOM 18 | print("Text is visible? " + str(textBoxState)) 19 | time.sleep(2) 20 | 21 | # Click the Hide button 22 | driver.find_element_by_id("hide-textbox").click() 23 | # Find the state of the text box 24 | textBoxState = textBoxElement.is_displayed() 25 | print("Text is visible? " + str(textBoxState)) 26 | time.sleep(2) 27 | 28 | # Added code to scroll up because the element was hiding behind the top navigation menu 29 | # You will learn about scrolling in future lecture 30 | driver.execute_script("window.scrollBy(0, -150);") 31 | # Click the Show button 32 | driver.find_element_by_id("show-textbox").click() 33 | # Find the state of the text box 34 | textBoxState = textBoxElement.is_displayed() 35 | print("Text is visible? " + str(textBoxState)) 36 | time.sleep(2) 37 | # Browser Close 38 | driver.quit() 39 | 40 | def testExpedia(self): 41 | baseUrl = "http://www.expedia.com" 42 | driver = webdriver.Firefox() 43 | driver.maximize_window() 44 | driver.get(baseUrl) 45 | driver.implicitly_wait(3) 46 | 47 | driver.find_element_by_id("tab-flight-tab").click() 48 | 49 | drpdwnElement = driver.find_element_by_id("flight-age-select-1") 50 | print("Element visible? " + str(drpdwnElement.is_displayed())) 51 | 52 | 53 | ff = HiddenElements() 54 | ff.testLetsKodeIt() 55 | ff.testExpedia() -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/11-Interview Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S18 - Selenium WebDriver -_ Working With Web Elements/11-Interview Questions.pdf -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/2-BrowserInteractions.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | class BrowserInteractions(): 4 | 5 | def test(self): 6 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 7 | driver = webdriver.Firefox() 8 | 9 | # Window Maximize 10 | driver.maximize_window() 11 | # Open the Url 12 | driver.get(baseUrl) 13 | # Get Title 14 | title = driver.title 15 | print("Title of the web page is: " + title) 16 | # Get Current Url 17 | currentUrl = driver.current_url 18 | print("Current Url of the web page is: " + currentUrl) 19 | # Browser Refresh 20 | driver.refresh() 21 | print("Browser Refreshed 1st time") 22 | driver.get(driver.current_url) 23 | print("Browser Refreshed 2nd time") 24 | # Open another Url 25 | driver.get("https://sso.teachable.com/secure/42299/users/sign_in?reset_purchase_session=1") 26 | currentUrl = driver.current_url 27 | print("Current Url of the web page is: " + currentUrl) 28 | # Browser Back 29 | driver.back() 30 | print("Go one step back in browser history") 31 | currentUrl = driver.current_url 32 | print("Current Url of the web page is: " + currentUrl) 33 | # Browser Forward 34 | driver.forward() 35 | print("Go one step forward in browser history") 36 | currentUrl = driver.current_url 37 | print("Current Url of the web page is: " + currentUrl) 38 | # Get Page Source 39 | pageSource = driver.page_source 40 | print(pageSource) 41 | # Browser Close / Quit 42 | # driver.close() 43 | driver.quit() 44 | 45 | ff = BrowserInteractions() 46 | ff.test() -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/3-ClickAndSendKeys.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class ClickAndSendKeys(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(10) 13 | 14 | loginLink = driver.find_element(By.XPATH, "//div[@id='navbar']//a[@href='/sign_in']") 15 | loginLink.click() 16 | 17 | emailField = driver.find_element(By.ID, "user_email") 18 | emailField.send_keys("test") 19 | 20 | passwordField = driver.find_element(By.ID, "user_password") 21 | passwordField.send_keys("test") 22 | 23 | time.sleep(3) 24 | 25 | emailField.clear() 26 | 27 | time.sleep(3) 28 | 29 | emailField.send_keys("test") 30 | 31 | 32 | 33 | ff = ClickAndSendKeys() 34 | ff.test() -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/4-ElementState.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | class ElementState(): 4 | 5 | def isEnabled(self): 6 | baseUrl = "http://www.google.com" 7 | driver = webdriver.Firefox() 8 | driver.maximize_window() 9 | driver.get(baseUrl) 10 | driver.implicitly_wait(3) 11 | 12 | e1 = driver.find_element_by_id("gs_htif0") 13 | e1State = e1.is_enabled() # True for enabled and False for disabled 14 | print("E1 is Enabled? -> " + str(e1State)) 15 | 16 | e2 = driver.find_element_by_id("gs_taif0") 17 | e2State = e2.is_enabled() # True for enabled and False for disabled 18 | print("E2 is Enabled? -> " + str(e2State)) 19 | 20 | e3 = driver.find_element_by_id("lst-ib") 21 | e3State = e3.is_enabled() # True for enabled and False for disabled 22 | print("E3 is Enabled? -> " + str(e3State)) 23 | 24 | e3.send_keys("letskodeit") 25 | 26 | 27 | 28 | e = ElementState() 29 | e.isEnabled() -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/5-RadioButtonsAndCheckboxes.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import time 3 | 4 | class RadioButtonsAndCheckboxes(): 5 | 6 | def test(self): 7 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | driver.get(baseUrl) 11 | driver.implicitly_wait(10) 12 | 13 | bmwRadioBtn = driver.find_element_by_id("bmwradio") 14 | bmwRadioBtn.click() 15 | 16 | time.sleep(2) 17 | benzRadioBtn = driver.find_element_by_id("benzradio") 18 | benzRadioBtn.click() 19 | 20 | time.sleep(2) 21 | bmwCheckbox = driver.find_element_by_id("bmwcheck") 22 | bmwCheckbox.click() 23 | 24 | time.sleep(2) 25 | benzCheckbox = driver.find_element_by_id("benzcheck") 26 | benzCheckbox.click() 27 | 28 | print("BMW Radio button is selected? " + str(bmwRadioBtn.is_selected())) # True if selected, False is not selected 29 | print("Benz Radio button is selected? " + str(benzRadioBtn.is_selected())) 30 | print("BMW Checkbox is selected? " + str(bmwCheckbox.is_selected())) 31 | print("Benz Checkbox is selected? " + str(benzCheckbox.is_selected())) 32 | 33 | ff = RadioButtonsAndCheckboxes() 34 | ff.test() 35 | -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/6-WorkingWithElementsList.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class WorkingWithElementsList(): 6 | 7 | def testListOfElements(self): 8 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(10) 13 | 14 | radioButtonsList = driver.find_elements( 15 | By.XPATH, "//input[contains(@type,'radio') and contains(@name,'cars')]") 16 | size = len(radioButtonsList) 17 | print("Size of the list: " + str(size)) 18 | 19 | for radioButton in radioButtonsList: 20 | isSelected = radioButton.is_selected() 21 | 22 | if not isSelected: 23 | radioButton.click() 24 | time.sleep(2) 25 | 26 | ff = WorkingWithElementsList() 27 | ff.testListOfElements() -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/8-DropdownSelect.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import time 3 | from selenium.webdriver.support.select import Select 4 | 5 | class DropdownSelect(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(10) 13 | 14 | element = driver.find_element_by_id("carselect") 15 | sel = Select(element) 16 | 17 | sel.select_by_value("benz") 18 | print("Select Benz by value") 19 | time.sleep(2) 20 | 21 | sel.select_by_index("2") 22 | print("Select Honda by index") 23 | time.sleep(2) 24 | 25 | sel.select_by_visible_text("BMW") 26 | print("Select BMW by visible text") 27 | time.sleep(2) 28 | 29 | sel.select_by_index(2) 30 | print("Select Honda by index") 31 | 32 | 33 | ff = DropdownSelect() 34 | ff.test() 35 | -------------------------------------------------------------------------------- /CODES/S18 - Selenium WebDriver -_ Working With Web Elements/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S18 - Selenium WebDriver -_ Working With Web Elements/Thumbs.db -------------------------------------------------------------------------------- /CODES/S2 - Setup And Configuration/5-Python-Mac-Setup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S2 - Setup And Configuration/5-Python-Mac-Setup.pdf -------------------------------------------------------------------------------- /CODES/S2 - Setup And Configuration/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S2 - Setup And Configuration/Thumbs.db -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/1_getText.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from utilities.handy_wrappers import HandyWrappers 4 | import time 5 | 6 | 7 | class GetText(): 8 | 9 | def test(self): 10 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 11 | driver = webdriver.Firefox() 12 | driver.maximize_window() 13 | driver.implicitly_wait(10) 14 | driver.get(baseUrl) 15 | 16 | openTabElement = driver.find_element(By.ID, "opentab") 17 | elementText = openTabElement.text 18 | print("Text on element is: " + elementText) 19 | time.sleep(1) 20 | driver.quit() 21 | 22 | 23 | ff = GetText() 24 | ff.test() -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/2_getAttribute.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | 6 | class GetAttribute(): 7 | 8 | def test(self): 9 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.implicitly_wait(10) 13 | driver.get(baseUrl) 14 | 15 | element = driver.find_element_by_id("name") 16 | result = element.get_attribute("type") 17 | 18 | print("Value of attribute is: " + result) 19 | time.sleep(1) 20 | driver.quit() 21 | 22 | 23 | ff = GetAttribute() 24 | ff.test() -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/3_handy-wrappers.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | 3 | class HandyWrappers(): 4 | 5 | def __init__(self, driver): 6 | self.driver = driver 7 | 8 | def getByType(self, locatorType): 9 | locatorType = locatorType.lower() 10 | if locatorType == "id": 11 | return By.ID 12 | elif locatorType == "name": 13 | return By.NAME 14 | elif locatorType == "xpath": 15 | return By.XPATH 16 | elif locatorType == "css": 17 | return By.CSS_SELECTOR 18 | elif locatorType == "classname": 19 | return By.CLASS_NAME 20 | elif locatorType == "linktext": 21 | return By.LINK_TEXT 22 | else: 23 | print("Locator type " + locatorType + " not correct/supported") 24 | return False 25 | 26 | def getElement(self, locator, locatorType="id"): 27 | element = None 28 | try: 29 | locatorType = locatorType.lower() 30 | byType = self.getByType(locatorType) 31 | element = self.driver.find_element(byType, locator) 32 | print("Element Found") 33 | except: 34 | print("Element not found") 35 | return element 36 | 37 | -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/4_element-present-check.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from utilities.handy_wrappers import HandyWrappers 4 | import time 5 | 6 | 7 | class ElementPresentCheck(): 8 | 9 | def test(self): 10 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 11 | driver = webdriver.Firefox() 12 | driver.maximize_window() 13 | driver.implicitly_wait(10) 14 | hw = HandyWrappers(driver) 15 | driver.get(baseUrl) 16 | 17 | elementResult1 = hw.isElementPresent("name", By.ID) 18 | print(str(elementResult1)) 19 | 20 | elementResult2 = hw.elementPresenceCheck("//input[@id='name1']", By.XPATH) 21 | print(str(elementResult2)) 22 | 23 | 24 | ff = ElementPresentCheck() 25 | ff.test() -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/4_handy-wrappers.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | 3 | class HandyWrappers(): 4 | 5 | def __init__(self, driver): 6 | self.driver = driver 7 | 8 | def getByType(self, locatorType): 9 | locatorType = locatorType.lower() 10 | if locatorType == "id": 11 | return By.ID 12 | elif locatorType == "name": 13 | return By.NAME 14 | elif locatorType == "xpath": 15 | return By.XPATH 16 | elif locatorType == "css": 17 | return By.CSS_SELECTOR 18 | elif locatorType == "classname": 19 | return By.CLASS_NAME 20 | elif locatorType == "linktext": 21 | return By.LINK_TEXT 22 | else: 23 | print("Locator type " + locatorType + " not correct/supported") 24 | return False 25 | 26 | def getElement(self, locator, locatorType="id"): 27 | element = None 28 | try: 29 | locatorType = locatorType.lower() 30 | byType = self.getByType(locatorType) 31 | element = self.driver.find_element(byType, locator) 32 | print("Element Found") 33 | except: 34 | print("Element not found") 35 | return element 36 | 37 | def isElementPresent(self, locator, byType): 38 | try: 39 | element = self.driver.find_element(byType, locator) 40 | if element is not None: 41 | print("Element Found") 42 | return True 43 | else: 44 | print("Element not found") 45 | return False 46 | except: 47 | print("Element not found") 48 | return False 49 | 50 | def elementPresenceCheck(self, locator, byType): 51 | try: 52 | elementList = self.driver.find_elements(byType, locator) 53 | if len(elementList) > 0: 54 | print("Element Found") 55 | return True 56 | else: 57 | print("Element not found") 58 | return False 59 | except: 60 | print("Element not found") 61 | return False 62 | -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/5_dynamic-xpath-format.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from utilities.handy_wrappers import HandyWrappers 4 | import time 5 | 6 | 7 | class DynamicXPathFormat(): 8 | 9 | def test(self): 10 | baseUrl = "https://letskodeit.teachable.com" 11 | driver = webdriver.Firefox() 12 | driver.maximize_window() 13 | driver.implicitly_wait(10) 14 | driver.get(baseUrl) 15 | 16 | # Login -> Lecture "How to click and type on a web element" 17 | driver.find_element(By.LINK_TEXT, "Login").click() 18 | email = driver.find_element(By.ID, "user_email") 19 | email.send_keys("test@email.com") 20 | password = driver.find_element(By.ID, "user_password") 21 | password.send_keys("abcabc") 22 | driver.find_element(By.NAME, "commit").click() 23 | 24 | # Search for courses -> You don't need to search the course 25 | # You can select it without searching also 26 | searchBox = driver.find_element(By.ID, "search-courses") 27 | searchBox.send_keys("JavaScript") 28 | 29 | # Select Course 30 | _course = "//div[contains(@class,'course-listing-title') and contains(text(),'{0}')]" 31 | _courseLocator = _course.format("JavaScript for beginners") 32 | 33 | courseElement = driver.find_element(By.XPATH, _courseLocator) 34 | courseElement.click() 35 | 36 | 37 | ff = DynamicXPathFormat() 38 | ff.test() -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/6-Interview Questions.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/6-Interview Questions.docx -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/6-Interview Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/6-Interview Questions.pdf -------------------------------------------------------------------------------- /CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S20 - Selenium WebDriver -_ Useful Methods And Properties/Thumbs.db -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/1-Wait Types.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S21 - Selenium WebDriver -_ Wait Types/1-Wait Types.pdf -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/2-implicit-wait-demo.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class ImplicitWaitDemo(): 6 | def test(self): 7 | baseUrl = "https://letskodeit.teachable.com" 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | driver.get(baseUrl) 11 | driver.implicitly_wait(10) 12 | 13 | loginLink = driver.find_element(By.XPATH, "//div[@id='navbar']//a[@href='/sign_in']") 14 | loginLink.click() 15 | 16 | emailField = driver.find_element(By.ID, "user_email") 17 | emailField.send_keys("test") 18 | 19 | ff = ImplicitWaitDemo() 20 | ff.test() -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/3-explicit-wait-demo1.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | from selenium.webdriver.support.ui import WebDriverWait 5 | from selenium.webdriver.support import expected_conditions as EC 6 | from selenium.common.exceptions import * 7 | 8 | class ExplicitWaitDemo1(): 9 | 10 | def test(self): 11 | baseUrl = "http://www.expedia.com" 12 | driver = webdriver.Firefox() 13 | driver.implicitly_wait(.5) 14 | driver.maximize_window() 15 | driver.get(baseUrl) 16 | driver.find_element(By.ID, "tab-flight-tab").click() 17 | driver.find_element(By.ID, "flight-origin").send_keys("SFO") 18 | driver.find_element(By.ID, "flight-destination").send_keys("NYC") 19 | driver.find_element(By.ID, "flight-departing").send_keys("12/24/2016") 20 | returnDate = driver.find_element(By.ID, "flight-returning") 21 | returnDate.clear() 22 | returnDate.send_keys("12/26/2016") 23 | driver.find_element(By.ID, "search-button").click() 24 | 25 | wait = WebDriverWait(driver, 10, poll_frequency=1, 26 | ignored_exceptions=[NoSuchElementException, 27 | ElementNotVisibleException, 28 | ElementNotSelectableException]) 29 | element = wait.until(EC.element_to_be_clickable((By.ID, 30 | "stopFilter_stops-0"))) 31 | element.click() 32 | 33 | time.sleep(2) 34 | driver.quit() 35 | 36 | ff = ExplicitWaitDemo1() 37 | ff.test() -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/4-explicit-wait-demo2.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from wait_types.explicit_wait_type import ExplicitWaitType 4 | import time 5 | 6 | class ExplicitWaitDemo2(): 7 | 8 | def test(self): 9 | baseUrl = "http://www.expedia.com" 10 | driver = webdriver.Firefox() 11 | driver.implicitly_wait(.5) 12 | driver.maximize_window() 13 | wait = ExplicitWaitType(driver) 14 | driver.get(baseUrl) 15 | driver.find_element(By.ID, "tab-flight-tab").click() 16 | driver.find_element(By.ID, "flight-origin").send_keys("SFO") 17 | driver.find_element(By.ID, "flight-destination").send_keys("NYC") 18 | driver.find_element(By.ID, "flight-departing").send_keys("12/24/2016") 19 | returnDate = driver.find_element(By.ID, "flight-returning") 20 | returnDate.clear() 21 | returnDate.send_keys("12/26/2016") 22 | driver.find_element(By.ID, "search-button").click() 23 | 24 | element = wait.waitForElement("stopFilter_stops-0") 25 | element.click() 26 | 27 | time.sleep(2) 28 | driver.quit() 29 | 30 | ff = ExplicitWaitDemo2() 31 | ff.test() -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/4-explicit-wait-type.py: -------------------------------------------------------------------------------- 1 | from traceback import print_stack 2 | from utilities.handy_wrappers import HandyWrappers 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.common.exceptions import * 6 | 7 | 8 | class ExplicitWaitType(): 9 | 10 | def __init__(self, driver): 11 | self.driver = driver 12 | self.hw = HandyWrappers(driver) 13 | 14 | 15 | def waitForElement(self, locator, locatorType="id", 16 | timeout=10, pollFrequency=0.5): 17 | element = None 18 | try: 19 | byType = self.hw.getByType(locatorType) 20 | print("Waiting for maximum :: " + str(timeout) + 21 | " :: seconds for element to be clickable") 22 | wait = WebDriverWait(self.driver, 10, poll_frequency=1, 23 | ignored_exceptions=[NoSuchElementException, 24 | ElementNotVisibleException, 25 | ElementNotSelectableException]) 26 | element = wait.until(EC.element_to_be_clickable((byType, 27 | "stopFilter_stops-0"))) 28 | print("Element appeared on the web page") 29 | except: 30 | print("Element not appeared on the web page") 31 | print_stack() 32 | return element -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/4-handy-wrappers.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | 3 | class HandyWrappers(): 4 | 5 | def __init__(self, driver): 6 | self.driver = driver 7 | 8 | def getByType(self, locatorType): 9 | locatorType = locatorType.lower() 10 | if locatorType == "id": 11 | return By.ID 12 | elif locatorType == "name": 13 | return By.NAME 14 | elif locatorType == "xpath": 15 | return By.XPATH 16 | elif locatorType == "css": 17 | return By.CSS_SELECTOR 18 | elif locatorType == "classname": 19 | return By.CLASS_NAME 20 | elif locatorType == "linktext": 21 | return By.LINK_TEXT 22 | else: 23 | print("Locator type " + locatorType + " not correct/supported") 24 | return False 25 | 26 | def getElement(self, locator, locatorType="id"): 27 | element = None 28 | try: 29 | locatorType = locatorType.lower() 30 | byType = self.getByType(locatorType) 31 | element = self.driver.find_element(byType, locator) 32 | print("Element Found") 33 | except: 34 | print("Element not found") 35 | return element 36 | 37 | -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/5-Interview Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S21 - Selenium WebDriver -_ Wait Types/5-Interview Questions.pdf -------------------------------------------------------------------------------- /CODES/S21 - Selenium WebDriver -_ Wait Types/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S21 - Selenium WebDriver -_ Wait Types/Thumbs.db -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/10_scrolling-element.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class ScrollingElement(): 6 | 7 | def test(self): 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | driver.get("https://letskodeit.teachable.com/pages/practice") 11 | driver.implicitly_wait(3) 12 | 13 | 14 | # Scroll Down 15 | driver.execute_script("window.scrollBy(0, 1000);") 16 | time.sleep(3) 17 | 18 | # Scroll Up 19 | driver.execute_script("window.scrollBy(0, -1000);") 20 | time.sleep(3) 21 | 22 | # Scroll Element Into View 23 | element = driver.find_element(By.ID, "mousehover") 24 | driver.execute_script("arguments[0].scrollIntoView(true);", element) 25 | time.sleep(2) 26 | driver.execute_script("window.scrollBy(0, -150);") 27 | 28 | # Native Way To Scroll Element Into View 29 | time.sleep(2) 30 | driver.execute_script("window.scrollBy(0, -1000);") 31 | location = element.location_once_scrolled_into_view 32 | print("Location: " + str(location)) 33 | driver.execute_script("window.scrollBy(0, -150);") 34 | 35 | 36 | 37 | ff = ScrollingElement() 38 | ff.test() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/11-Interview Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S22 - Selenium WebDriver -_ Advanced/11-Interview Questions.pdf -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/2_calendar-selection.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class CalendarSelection(): 6 | 7 | def test1(self): 8 | baseUrl = "http://www.expedia.com" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(3) 13 | 14 | # Click flights tab 15 | driver.find_element_by_id("tab-flight-tab").click() 16 | # Find departing field 17 | departingField = driver.find_element_by_id("flight-departing") 18 | # Click departing field 19 | departingField.click() 20 | # Find the date to be selected 21 | # Expedia website has changed the DOM after the lecture was made 22 | # Updated new xpath 23 | dateToSelect = driver.find_element(By.XPATH, 24 | "(//div[@class='datepicker-cal-month'])[1]//button[text()='30']") 25 | # Click the date 26 | dateToSelect.click() 27 | 28 | time.sleep(3) 29 | driver.quit() 30 | 31 | ff = CalendarSelection() 32 | ff.test1() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/3_calendar-selection.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class CalendarSelection(): 6 | 7 | def test1(self): 8 | baseUrl = "http://www.expedia.com" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(3) 13 | 14 | # Click flights tab 15 | driver.find_element_by_id("tab-flight-tab").click() 16 | # Find departing field 17 | departingField = driver.find_element_by_id("flight-departing") 18 | # Click departing field 19 | departingField.click() 20 | # Find the date to be selected 21 | # Expedia website has changed the DOM after the lecture was made 22 | # Updated new xpath 23 | dateToSelect = driver.find_element(By.XPATH, 24 | "(//div[@class='datepicker-cal-month'])[1]//button[text()='30']") 25 | # Click the date 26 | dateToSelect.click() 27 | 28 | time.sleep(3) 29 | driver.quit() 30 | 31 | def test2(self): 32 | baseUrl = "http://www.expedia.com" 33 | driver = webdriver.Firefox() 34 | driver.maximize_window() 35 | driver.get(baseUrl) 36 | driver.implicitly_wait(3) 37 | 38 | # Click flights tab 39 | driver.find_element_by_id("tab-flight-tab").click() 40 | # Click departing field 41 | driver.find_element_by_id("flight-departing").click() 42 | # Expedia website has changed the DOM after the lecture was made 43 | # Updated new xpath 44 | calMonth = driver.find_element(By.XPATH, "(//div[@class='datepicker-cal-month'])[1]") 45 | allValidDates = calMonth.find_elements(By.TAG_NAME, "button") 46 | 47 | time.sleep(2) 48 | 49 | for date in allValidDates: 50 | if date.text == "30": 51 | date.click() 52 | break 53 | 54 | ff = CalendarSelection() 55 | ff.test2() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/5_auto-complete.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class AutoComplete(): 6 | 7 | def test(self): 8 | baseUrl = "http://www.southwest.com" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(3) 13 | 14 | # Send Partial Data 15 | cityField = driver.find_element_by_id("air-city-departure") 16 | cityField.send_keys("New York") 17 | time.sleep(3) 18 | # Find the item and click 19 | itemToSelect = driver.find_element_by_xpath("//ul[@id='air-city-departure-menu']//li[contains(text(),'NJ - EWR')]") 20 | itemToSelect.click() 21 | 22 | # time.sleep(3) 23 | # driver.quit() 24 | 25 | ff = AutoComplete() 26 | ff.test() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/6_screenshots.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class Screenshots(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com/" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(3) 13 | 14 | driver.find_element(By.LINK_TEXT, "Login").click() 15 | driver.find_element(By.ID, "user_email").send_keys("abc@email.com") 16 | driver.find_element(By.ID, "user_password").send_keys("abc") 17 | driver.find_element(By.NAME, "commit").click() 18 | destinationFileName = "/Users/atomar/Desktop/test.png" # Mac 19 | # destinationFileName = "C:\\atomar\\Desktop" -> Windows 20 | 21 | try: 22 | driver.save_screenshot(destinationFileName) 23 | print("Screenshot saved to directory --> :: " + destinationFileName) 24 | except NotADirectoryError: 25 | print("Not a directory issue") 26 | 27 | ff = Screenshots() 28 | ff.test() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/7_screenshots-generic.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class Screenshots(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com/" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.implicitly_wait(3) 13 | 14 | driver.find_element(By.LINK_TEXT, "Login").click() 15 | driver.find_element(By.ID, "user_email").send_keys("abc@email.com") 16 | driver.find_element(By.ID, "user_password").send_keys("abc") 17 | driver.find_element(By.NAME, "commit").click() 18 | self.takeScreenshot(driver) 19 | 20 | 21 | 22 | def takeScreenshot(self, driver): 23 | """ 24 | Takes screenshot of the current open web page 25 | :param driver 26 | :return: 27 | """ 28 | fileName = str(round(time.time() * 1000)) + ".png" 29 | screenshotDirectory = "/Users/atomar/desktop/" 30 | destinationFile = screenshotDirectory + fileName 31 | 32 | try: 33 | driver.save_screenshot(destinationFile) 34 | print("Screenshot saved to directory --> :: " + destinationFile) 35 | except NotADirectoryError: 36 | print("Not a directory issue") 37 | 38 | ff = Screenshots() 39 | ff.test() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/8_javascript-execution.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class JavaScriptExecution(): 6 | 7 | def test(self): 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | # driver.get("https://letskodeit.teachable.com/pages/practice") 11 | driver.execute_script("window.location = 'https://letskodeit.teachable.com/pages/practice';") 12 | driver.implicitly_wait(3) 13 | 14 | # element = driver.find_element(By.ID, "name") 15 | element = driver.execute_script("return document.getElementById('name');") 16 | element.send_keys("Test") 17 | 18 | 19 | 20 | 21 | 22 | ff = JavaScriptExecution() 23 | ff.test() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/9_window-size.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class WindowSize(): 6 | 7 | def test(self): 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | driver.get("https://letskodeit.teachable.com/pages/practice") 11 | driver.implicitly_wait(3) 12 | 13 | 14 | height = driver.execute_script("return window.innerHeight;") 15 | width = driver.execute_script("return window.innerWidth;") 16 | print("Height: " + str(height)) 17 | print("Width: " + str(width)) 18 | driver.quit() 19 | 20 | 21 | ff = WindowSize() 22 | ff.test() -------------------------------------------------------------------------------- /CODES/S22 - Selenium WebDriver -_ Advanced/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S22 - Selenium WebDriver -_ Advanced/Thumbs.db -------------------------------------------------------------------------------- /CODES/S23 - Selenium WebDriver -_ Switch Window And IFrames/1_switch-to-window.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class SwitchToWindow(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | 13 | # Find parent handle -> Main Window 14 | parentHandle = driver.current_window_handle 15 | print("Parent Handle: " + parentHandle) 16 | 17 | # Find open window button and click it 18 | driver.find_element(By.ID, "openwindow").click() 19 | time.sleep(2) 20 | 21 | # Find all handles, there should two handles after clicking open window button 22 | handles = driver.window_handles 23 | 24 | # Switch to window and search course 25 | for handle in handles: 26 | print("Handle: " + handle) 27 | 28 | ff = SwitchToWindow() 29 | ff.test() -------------------------------------------------------------------------------- /CODES/S23 - Selenium WebDriver -_ Switch Window And IFrames/2_switch-to-window.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class SwitchToWindow(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | 13 | # Find parent handle -> Main Window 14 | parentHandle = driver.current_window_handle 15 | print("Parent Handle: " + parentHandle) 16 | 17 | # Find open window button and click it 18 | driver.find_element(By.ID, "openwindow").click() 19 | time.sleep(2) 20 | 21 | # Find all handles, there should two handles after clicking open window button 22 | handles = driver.window_handles 23 | 24 | # Switch to window and search course 25 | for handle in handles: 26 | print("Handle: " + handle) 27 | if handle not in parentHandle: 28 | driver.switch_to.window(handle) 29 | print("Switched to window:: " + handle) 30 | searchBox = driver.find_element(By.ID, "search-courses") 31 | searchBox.send_keys("python") 32 | time.sleep(2) 33 | driver.close() 34 | break 35 | 36 | # Switch back to the parent handle 37 | driver.switch_to.window(parentHandle) 38 | driver.find_element(By.ID, "name").send_keys("Test Successful") 39 | 40 | 41 | 42 | 43 | 44 | 45 | ff = SwitchToWindow() 46 | ff.test() -------------------------------------------------------------------------------- /CODES/S23 - Selenium WebDriver -_ Switch Window And IFrames/3_switch-to-frame.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class SwitchToFrame(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.execute_script("window.scrollBy(0, 1000);") 13 | 14 | # Switch to frame using Id 15 | 16 | # Switch to frame using name 17 | 18 | # Switch to frame using numbers 19 | 20 | # Search course 21 | 22 | # Switch back to the parent frame 23 | searchBox = driver.find_element(By.ID, "search-courses") 24 | searchBox.send_keys("python") 25 | 26 | 27 | ff = SwitchToFrame() 28 | ff.test() 29 | -------------------------------------------------------------------------------- /CODES/S23 - Selenium WebDriver -_ Switch Window And IFrames/4_switch-to-frame.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class SwitchToFrame(): 6 | 7 | def test(self): 8 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | driver.execute_script("window.scrollBy(0, 1000);") 13 | 14 | # Switch to frame using Id 15 | driver.switch_to.frame("courses-iframe") 16 | 17 | # Switch to frame using name 18 | # driver.switch_to.frame("iframe-name") 19 | 20 | # Switch to frame using numbers 21 | # driver.switch_to.frame(0) 22 | 23 | time.sleep(2) 24 | # Search course 25 | searchBox = driver.find_element(By.ID, "search-courses") 26 | searchBox.send_keys("python") 27 | time.sleep(2) 28 | 29 | # Switch back to the parent frame 30 | driver.switch_to.default_content() 31 | driver.execute_script("window.scrollBy(0, -1000);") 32 | time.sleep(2) 33 | driver.find_element(By.ID, "name").send_keys("Test Successful") 34 | 35 | 36 | 37 | 38 | ff = SwitchToFrame() 39 | ff.test() -------------------------------------------------------------------------------- /CODES/S23 - Selenium WebDriver -_ Switch Window And IFrames/5_switch-to-alert.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | import time 4 | 5 | class SwitchToFrame(): 6 | 7 | def test1(self): 8 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 9 | driver = webdriver.Firefox() 10 | driver.maximize_window() 11 | driver.get(baseUrl) 12 | 13 | 14 | driver.find_element(By.ID, "name").send_keys("Anil") 15 | driver.find_element(By.ID, "alertbtn").click() 16 | time.sleep(2) 17 | alert1 = driver.switch_to.alert 18 | alert1.accept() 19 | time.sleep(2) 20 | driver.find_element(By.ID, "name").send_keys("Anil") 21 | driver.find_element(By.ID, "confirmbtn").click() 22 | time.sleep(2) 23 | alert2 = driver.switch_to.alert 24 | alert2.dismiss() 25 | 26 | 27 | 28 | ff = SwitchToFrame() 29 | ff.test1() -------------------------------------------------------------------------------- /CODES/S23 - Selenium WebDriver -_ Switch Window And IFrames/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S23 - Selenium WebDriver -_ Switch Window And IFrames/Thumbs.db -------------------------------------------------------------------------------- /CODES/S24 - Selenium WebDriver -_ Working With Actions Class/1-mouse-hovering.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver import ActionChains 4 | import time 5 | 6 | class MouseHovering(): 7 | 8 | def test1(self): 9 | baseUrl = "https://letskodeit.teachable.com/pages/practice" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.get(baseUrl) 13 | driver.implicitly_wait(3) 14 | 15 | driver.execute_script("window.scrollBy(0, 600);") 16 | time.sleep(2) 17 | element = driver.find_element(By.ID, "mousehover") 18 | itemToClickLocator = ".//div[@class='mouse-hover-content']//a[text()='Top']" 19 | try: 20 | actions = ActionChains(driver) 21 | actions.move_to_element(element).perform() 22 | print("Mouse Hovered on element") 23 | time.sleep(2) 24 | topLink = driver.find_element(By.XPATH, itemToClickLocator) 25 | actions.move_to_element(topLink).click().perform() 26 | print("Item Clicked") 27 | except: 28 | print("Mouse Hover failed on element") 29 | 30 | ff = MouseHovering() 31 | ff.test1() -------------------------------------------------------------------------------- /CODES/S24 - Selenium WebDriver -_ Working With Actions Class/2-drag-and-drop.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver import ActionChains 4 | import time 5 | 6 | class DragAndDrop(): 7 | 8 | def test1(self): 9 | baseUrl = "https://jqueryui.com/droppable/" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.get(baseUrl) 13 | driver.implicitly_wait(3) 14 | 15 | driver.switch_to.frame(0) 16 | 17 | fromElement = driver.find_element(By.ID, "draggable") 18 | toElement = driver.find_element(By.ID, "droppable") 19 | time.sleep(2) 20 | try: 21 | actions = ActionChains(driver) 22 | actions.drag_and_drop(fromElement, toElement).perform() 23 | # actions.click_and_hold(fromElement).move_to_element(toElement).release().perform() 24 | print("Drag And Drop Element Successful") 25 | time.sleep(2) 26 | except: 27 | print("Drag And Drop failed on element") 28 | 29 | ff = DragAndDrop() 30 | ff.test1() -------------------------------------------------------------------------------- /CODES/S24 - Selenium WebDriver -_ Working With Actions Class/3-sliders.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from selenium.webdriver import ActionChains 4 | import time 5 | 6 | class Sliders(): 7 | 8 | def test1(self): 9 | baseUrl = "https://jqueryui.com/slider/" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.get(baseUrl) 13 | driver.implicitly_wait(3) 14 | 15 | driver.switch_to.frame(0) 16 | 17 | element = driver.find_element(By.XPATH, "//div[@id='slider']//span") 18 | time.sleep(2) 19 | try: 20 | actions = ActionChains(driver) 21 | actions.drag_and_drop_by_offset(element, 100, 0).perform() 22 | print("Sliding Element Successful") 23 | time.sleep(2) 24 | except: 25 | print("Sliding failed on element") 26 | 27 | ff = Sliders() 28 | ff.test1() -------------------------------------------------------------------------------- /CODES/S24 - Selenium WebDriver -_ Working With Actions Class/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S24 - Selenium WebDriver -_ Working With Actions Class/Thumbs.db -------------------------------------------------------------------------------- /CODES/S25 - Logging Infrastructure/Please Read.txt: -------------------------------------------------------------------------------- 1 | Please get these lectures from Python 3 course which has been previously provided -------------------------------------------------------------------------------- /CODES/S26 - Unittest Infrastructure/26.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S26 - Unittest Infrastructure/26.jpg -------------------------------------------------------------------------------- /CODES/S26 - Unittest Infrastructure/5 - How to set project directory path - Windows.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S26 - Unittest Infrastructure/5 - How to set project directory path - Windows.pdf -------------------------------------------------------------------------------- /CODES/S26 - Unittest Infrastructure/Please Read.txt: -------------------------------------------------------------------------------- 1 | Please get these lectures from Python 3 course which has been previously provided -------------------------------------------------------------------------------- /CODES/S26 - Unittest Infrastructure/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S26 - Unittest Infrastructure/Thumbs.db -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/1-test-case-demo1.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.fixture() 4 | def setUp(): 5 | print("Running demo1 setUp") 6 | 7 | def test_demo1_methodA(setUp): 8 | print("Running demo1 method A") 9 | 10 | def test_demo1_methodB(setUp): 11 | print("Running demo1 method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/10 - Installing PyTest HTML Plugin.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S27 - Pytest -_ Advanced Testing Framework/10 - Installing PyTest HTML Plugin.docx -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/10 - Installing PyTest HTML Plugin.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S27 - Pytest -_ Advanced Testing Framework/10 - Installing PyTest HTML Plugin.pdf -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/11-class-to-test.py: -------------------------------------------------------------------------------- 1 | """ 2 | How to use test class to wrap methods under one class 3 | Learn about autouse keywords in fixtures 4 | Assert the result to create a real test scenario 5 | """ 6 | 7 | class SomeClassToTest(): 8 | 9 | def __init__(self, value): 10 | self.value = value 11 | 12 | 13 | def sumNumbers(self, a, b): 14 | return a + b + self.value -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/11-conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.yield_fixture() 4 | def setUp(): 5 | print("Running method level setUp") 6 | yield 7 | print("Running method level tearDown") 8 | 9 | 10 | @pytest.yield_fixture(scope="class") 11 | def oneTimeSetUp(request, browser): 12 | print("Running one time setUp") 13 | if browser == 'firefox': 14 | value = 10 15 | print("Running tests on FF") 16 | else: 17 | value = 20 18 | print("Running tests on chrome") 19 | 20 | if request.cls is not None: 21 | request.cls.value = value 22 | 23 | yield value 24 | print("Running one time tearDown") 25 | 26 | def pytest_addoption(parser): 27 | parser.addoption("--browser") 28 | parser.addoption("--osType", help="Type of operating system") 29 | 30 | @pytest.fixture(scope="session") 31 | def browser(request): 32 | return request.config.getoption("--browser") 33 | 34 | @pytest.fixture(scope="session") 35 | def osType(request): 36 | return request.config.getoption("--osType") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/11-test-reporting-demo.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from pytestpackage.class_to_test import SomeClassToTest 3 | 4 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 5 | class TestReportingDemo(): 6 | 7 | @pytest.fixture(autouse=True) 8 | def classSetup(self): 9 | self.abc = SomeClassToTest(10) 10 | 11 | def test_methodA(self): 12 | result = self.abc.sumNumbers(2, 8) 13 | assert result == 20 14 | print("Running method A") 15 | 16 | def test_methodB(self): 17 | result = self.abc.sumNumbers(2, 8) 18 | assert result > 20 19 | print("Running method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/2 - PyTest Naming Conventions.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S27 - Pytest -_ Advanced Testing Framework/2 - PyTest Naming Conventions.docx -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/2 - PyTest Naming Conventions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S27 - Pytest -_ Advanced Testing Framework/2 - PyTest Naming Conventions.pdf -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/2 - PyTest Naming Conventions_page-0001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S27 - Pytest -_ Advanced Testing Framework/2 - PyTest Naming Conventions_page-0001.jpg -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/3-test-case-demo2.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | @pytest.yield_fixture() 3 | def setUp(): 4 | print("Running demo2 setUp") 5 | yield 6 | print("Running demo2 tearDown") 7 | 8 | def test_demo2_methodA(setUp): 9 | print("Running demo2 method A") 10 | 11 | def test_demo2_methodB(setUp): 12 | print("Running demo2 method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/4-test-case-demo1.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.fixture() 4 | def setUp(): 5 | print("Running demo1 setUp") 6 | 7 | def test_demo1_methodA(setUp): 8 | print("Running demo1 method A") 9 | 10 | def test_demo1_methodB(setUp): 11 | print("Running demo1 method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/4-test-case-demo2.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | @pytest.yield_fixture() 3 | def setUp(): 4 | print("Running demo2 setUp") 5 | yield 6 | print("Running demo2 tearDown") 7 | 8 | def test_demo2_methodA(setUp): 9 | print("Running demo2 method A") 10 | 11 | def test_demo2_methodB(setUp): 12 | print("Running demo2 method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/4-test-case-demo3.py: -------------------------------------------------------------------------------- 1 | """ 2 | file name should start with test 3 | test method name should start with test 4 | 5 | py.test test_mod.py # run tests in module 6 | py.test somepath # run all tests below somepath 7 | py.test test_module.py::test_method # only run test_method in test_module 8 | 9 | -s to print statements 10 | -v verbose 11 | """ 12 | 13 | import pytest 14 | 15 | @pytest.yield_fixture() 16 | def setUp(): 17 | print("Running demo3 setUp") 18 | yield 19 | print("Running demo3 tearDown") 20 | 21 | def test_demo3_methodA(setUp): 22 | print("Running demo3 method A") 23 | 24 | def test_demo3_methodB(setUp): 25 | print("Running demo3 method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/5-conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.yield_fixture() 4 | def setUp(): 5 | print("Running method level setUp") 6 | yield 7 | print("Running method level tearDown") 8 | 9 | 10 | @pytest.yield_fixture(scope="module") 11 | def oneTimeSetUp(): 12 | print("Running conftest demo one time setUp") 13 | yield 14 | print("Running conftest demo one time tearDown") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/5-test-conftest-demo1.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | def test_demo1_methodA(oneTimeSetUp, setUp): 4 | print("Running conftest demo1 method A") 5 | 6 | def test_demo1_methodB(oneTimeSetUp, setUp): 7 | print("Running conftest demo1 method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/5-test-conftest-demo2.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | def test_demo2_methodA(oneTimeSetUp, setUp): 4 | print("Running conftest demo2 method A") 5 | 6 | def test_demo3_methodB(oneTimeSetUp, setUp): 7 | print("Running conftest demo2 method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/6-conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.yield_fixture() 4 | def setUp(): 5 | print("Running method level setUp") 6 | yield 7 | print("Running method level tearDown") 8 | 9 | 10 | @pytest.yield_fixture(scope="module") 11 | def oneTimeSetUp(): 12 | print("Running conftest demo one time setUp") 13 | yield 14 | print("Running conftest demo one time tearDown") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/6-test-run-order-demo.py: -------------------------------------------------------------------------------- 1 | """ 2 | http://pytest-ordering.readthedocs.io/en/develop/ 3 | """ 4 | 5 | import pytest 6 | 7 | # B, A, C, E, D, F 8 | @pytest.mark.run(order=2) 9 | def test_run_order_methodA(oneTimeSetUp, setUp): 10 | print("Running method A") 11 | 12 | @pytest.mark.run(order=1) 13 | def test_run_order_methodB(oneTimeSetUp, setUp): 14 | print("Running method B") 15 | 16 | @pytest.mark.run(order=3) 17 | def test_run_order_methodC(oneTimeSetUp, setUp): 18 | print("Running method C") 19 | 20 | @pytest.mark.run(order=5) 21 | def test_run_order_methodD(oneTimeSetUp, setUp): 22 | print("Running method D") 23 | 24 | @pytest.mark.run(order=4) 25 | def test_run_order_methodE(oneTimeSetUp, setUp): 26 | print("Running method E") 27 | 28 | @pytest.mark.run(order=6) 29 | def test_run_order_methodF(oneTimeSetUp, setUp): 30 | print("Running method F") 31 | 32 | -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/7-conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.yield_fixture() 4 | def setUp(): 5 | print("Running method level setUp") 6 | yield 7 | print("Running method level tearDown") 8 | 9 | 10 | @pytest.yield_fixture(scope="module") 11 | def oneTimeSetUp(browser, osType): 12 | if browser == 'firefox': 13 | print("Running tests on FF") 14 | else: 15 | print("Running tests on chrome") 16 | 17 | def pytest_addoption(parser): 18 | parser.addoption("--browser") 19 | parser.addoption("--osType", help="Type of operating system") 20 | 21 | @pytest.fixture(scope="session") 22 | def browser(request): 23 | return request.config.getoption("--browser") 24 | 25 | @pytest.fixture(scope="session") 26 | def osType(request): 27 | return request.config.getoption("--osType") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/7-test-command-line-args.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | def test_command_line_methodA(oneTimeSetUp, setUp): 4 | print("Running method A") 5 | 6 | def test_command_line_methodB(oneTimeSetUp, setUp): 7 | print("Running method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/8-class-to-test.py: -------------------------------------------------------------------------------- 1 | """ 2 | How to use test class to wrap methods under one class 3 | Learn about autouse keywords in fixtures 4 | Assert the result to create a real test scenario 5 | """ 6 | 7 | class SomeClassToTest(): 8 | 9 | def __init__(self, value): 10 | self.value = value 11 | 12 | 13 | def sumNumbers(self, a, b): 14 | return a + b + self.value -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/8-conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.yield_fixture() 4 | def setUp(): 5 | print("Running method level setUp") 6 | yield 7 | print("Running method level tearDown") 8 | 9 | 10 | @pytest.yield_fixture(scope="class") 11 | def oneTimeSetUp(browser): 12 | print("Running one time setUp") 13 | if browser == 'firefox': 14 | print("Running tests on FF") 15 | else: 16 | print("Running tests on chrome") 17 | yield 18 | print("Running one time tearDown") 19 | 20 | def pytest_addoption(parser): 21 | parser.addoption("--browser") 22 | parser.addoption("--osType", help="Type of operating system") 23 | 24 | @pytest.fixture(scope="session") 25 | def browser(request): 26 | return request.config.getoption("--browser") 27 | 28 | @pytest.fixture(scope="session") 29 | def osType(request): 30 | return request.config.getoption("--osType") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/8-test-class-demo1.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from pytestpackage.class_to_test import SomeClassToTest 3 | 4 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 5 | class TestClassDemo(): 6 | 7 | @pytest.fixture(autouse=True) 8 | def classSetup(self): 9 | self.abc = SomeClassToTest(10) 10 | 11 | def test_methodA(self): 12 | result = self.abc.sumNumbers(2, 8) 13 | assert result == 20 14 | print("Running method A") 15 | 16 | def test_methodB(self): 17 | print("Running method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/9-class-to-test.py: -------------------------------------------------------------------------------- 1 | """ 2 | How to use test class to wrap methods under one class 3 | Learn about autouse keywords in fixtures 4 | Assert the result to create a real test scenario 5 | """ 6 | 7 | class SomeClassToTest(): 8 | 9 | def __init__(self, value): 10 | self.value = value 11 | 12 | 13 | def sumNumbers(self, a, b): 14 | return a + b + self.value -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/9-conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | @pytest.yield_fixture() 4 | def setUp(): 5 | print("Running method level setUp") 6 | yield 7 | print("Running method level tearDown") 8 | 9 | 10 | @pytest.yield_fixture(scope="class") 11 | def oneTimeSetUp(request, browser): 12 | print("Running one time setUp") 13 | if browser == 'firefox': 14 | value = 10 15 | print("Running tests on FF") 16 | else: 17 | value = 20 18 | print("Running tests on chrome") 19 | 20 | if request.cls is not None: 21 | request.cls.value = value 22 | 23 | yield value 24 | print("Running one time tearDown") 25 | 26 | def pytest_addoption(parser): 27 | parser.addoption("--browser") 28 | parser.addoption("--osType", help="Type of operating system") 29 | 30 | @pytest.fixture(scope="session") 31 | def browser(request): 32 | return request.config.getoption("--browser") 33 | 34 | @pytest.fixture(scope="session") 35 | def osType(request): 36 | return request.config.getoption("--osType") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/9-test-class-demo2.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from pytestpackage.class_to_test import SomeClassToTest 3 | 4 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 5 | class TestClassDemo(): 6 | 7 | @pytest.fixture(autouse=True) 8 | def classSetup(self, oneTimeSetUp): 9 | self.abc = SomeClassToTest(self.value) 10 | 11 | def test_methodA(self): 12 | result = self.abc.sumNumbers(2, 8) 13 | assert result == 20 14 | print("Running method A") 15 | 16 | def test_methodB(self): 17 | print("Running method B") -------------------------------------------------------------------------------- /CODES/S27 - Pytest -_ Advanced Testing Framework/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S27 - Pytest -_ Advanced Testing Framework/Thumbs.db -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/3_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | 4 | class LoginTests(): 5 | 6 | def test_validLogin(self): 7 | baseURL = "https://letskodeit.teachable.com/" 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | driver.implicitly_wait(3) 11 | driver.get(baseURL) 12 | 13 | loginLink = driver.find_element(By.LINK_TEXT, "Login") 14 | loginLink.click() 15 | 16 | emailField = driver.find_element(By.ID, "user_email") 17 | emailField.send_keys("test@email.com") 18 | 19 | passwordField = driver.find_element(By.ID, "user_password") 20 | passwordField.send_keys("abcabc") 21 | 22 | loginButton = driver.find_element(By.NAME, "commit") 23 | loginButton.click() 24 | 25 | userIcon = driver.find_element(By.XPATH, ".//*[@id='navbar']//span[text()='User Settings']") 26 | if userIcon is not None: 27 | print("Login Successful") 28 | else: 29 | print("Login Failed") 30 | 31 | ff = LoginTests() 32 | ff.test_validLogin() -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/4_login_page.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | 3 | class LoginPage(): 4 | 5 | def __init__(self, driver): 6 | self.driver = driver 7 | 8 | def login(self, username, password): 9 | loginLink = self.driver.find_element(By.LINK_TEXT, "Login") 10 | loginLink.click() 11 | 12 | emailField = self.driver.find_element(By.ID, "user_email") 13 | emailField.send_keys(username) 14 | 15 | passwordField = self.driver.find_element(By.ID, "user_password") 16 | passwordField.send_keys(password) 17 | 18 | loginButton = self.driver.find_element(By.NAME, "commit") 19 | loginButton.click() 20 | -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/4_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from pages.home.login_page import LoginPage 4 | import unittest 5 | 6 | class LoginTests(unittest.TestCase): 7 | 8 | def test_validLogin(self): 9 | baseURL = "https://letskodeit.teachable.com/" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.implicitly_wait(3) 13 | driver.get(baseURL) 14 | 15 | lp = LoginPage(driver) 16 | lp.login("test@email.com", "abcabc") 17 | 18 | 19 | userIcon = driver.find_element(By.XPATH, ".//*[@id='navbar']//span[text()='User Settings']") 20 | if userIcon is not None: 21 | print("Login Successful") 22 | else: 23 | print("Login Failed") -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/5_login_page.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | 3 | class LoginPage(): 4 | 5 | def __init__(self, driver): 6 | self.driver = driver 7 | 8 | # Locators 9 | _login_link = "Login" 10 | _email_field = "user_email" 11 | _password_field = "user_password" 12 | _login_button = "commit" 13 | 14 | def getLoginLink(self): 15 | return self.driver.find_element(By.LINK_TEXT, self._login_link) 16 | 17 | def getEmailField(self): 18 | return self.driver.find_element(By.ID, self._email_field) 19 | 20 | def getPasswordField(self): 21 | return self.driver.find_element(By.ID, self._password_field) 22 | 23 | def getLoginButton(self): 24 | return self.driver.find_element(By.NAME, self._login_button) 25 | 26 | def clickLoginLink(self): 27 | self.getLoginLink().click() 28 | 29 | def enterEmail(self, email): 30 | self.getEmailField().send_keys(email) 31 | 32 | def enterPassword(self, password): 33 | self.getPasswordField().send_keys(password) 34 | 35 | def clickLoginButton(self): 36 | self.getLoginButton().click() 37 | 38 | def login(self, email, password): 39 | self.clickLoginLink() 40 | self.enterEmail(email) 41 | self.enterPassword(password) 42 | self.clickLoginButton() -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/6_selenium_driver.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | from traceback import print_stack 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | from selenium.common.exceptions import * 6 | 7 | class SeleniumDriver(): 8 | 9 | def __init__(self, driver): 10 | self.driver = driver 11 | 12 | def getByType(self, locatorType): 13 | locatorType = locatorType.lower() 14 | if locatorType == "id": 15 | return By.ID 16 | elif locatorType == "name": 17 | return By.NAME 18 | elif locatorType == "xpath": 19 | return By.XPATH 20 | elif locatorType == "css": 21 | return By.CSS_SELECTOR 22 | elif locatorType == "classname": 23 | return By.CLASS_NAME 24 | elif locatorType == "linktext": 25 | return By.LINK_TEXT 26 | else: 27 | print("Locator type " + locatorType + " not correct/supported") 28 | return False 29 | 30 | def getElement(self, locator, locatorType="id"): 31 | element = None 32 | try: 33 | locatorType = locatorType.lower() 34 | byType = self.getByType(locatorType) 35 | element = self.driver.find_element(byType, locator) 36 | print("Element Found") 37 | except: 38 | print("Element not found") 39 | return element 40 | 41 | def elementClick(self, locator, locatorType="id"): 42 | try: 43 | element = self.getElement(locator, locatorType) 44 | element.click() 45 | print("Clicked on element with locator: " + locator + " locatorType: " + locatorType) 46 | except: 47 | print("Cannot click on the element with locator: " + locator + " locatorType: " + locatorType) 48 | print_stack() 49 | 50 | def isElementPresent(self, locator, byType): 51 | try: 52 | element = self.driver.find_element(byType, locator) 53 | if element is not None: 54 | print("Element Found") 55 | return True 56 | else: 57 | print("Element not found") 58 | return False 59 | except: 60 | print("Element not found") 61 | return False 62 | 63 | def elementPresenceCheck(self, locator, byType): 64 | try: 65 | elementList = self.driver.find_elements(byType, locator) 66 | if len(elementList) > 0: 67 | print("Element Found") 68 | return True 69 | else: 70 | print("Element not found") 71 | return False 72 | except: 73 | print("Element not found") 74 | return False 75 | 76 | def waitForElement(self, locator, locatorType="id", 77 | timeout=10, pollFrequency=0.5): 78 | element = None 79 | try: 80 | byType = self.getByType(locatorType) 81 | print("Waiting for maximum :: " + str(timeout) + 82 | " :: seconds for element to be clickable") 83 | wait = WebDriverWait(self.driver, 10, poll_frequency=1, 84 | ignored_exceptions=[NoSuchElementException, 85 | ElementNotVisibleException, 86 | ElementNotSelectableException]) 87 | element = wait.until(EC.element_to_be_clickable((byType, 88 | "stopFilter_stops-0"))) 89 | print("Element appeared on the web page") 90 | except: 91 | print("Element not appeared on the web page") 92 | print_stack() 93 | return element 94 | -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/7_login_page.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | from base.selenium_driver import SeleniumDriver 3 | 4 | class LoginPage(SeleniumDriver): 5 | 6 | def __init__(self, driver): 7 | super().__init__(driver) 8 | self.driver = driver 9 | 10 | # Locators 11 | _login_link = "Login" 12 | _email_field = "user_email" 13 | _password_field = "user_password" 14 | _login_button = "commit" 15 | 16 | # def getLoginLink(self): 17 | # return self.driver.find_element(By.LINK_TEXT, self._login_link) 18 | # 19 | # def getEmailField(self): 20 | # return self.driver.find_element(By.ID, self._email_field) 21 | # 22 | # def getPasswordField(self): 23 | # return self.driver.find_element(By.ID, self._password_field) 24 | # 25 | # def getLoginButton(self): 26 | # return self.driver.find_element(By.NAME, self._login_button) 27 | 28 | def clickLoginLink(self): 29 | self.elementClick(self._login_link, locatorType="link") 30 | 31 | def enterEmail(self, email): 32 | self.sendKeys(email, self._email_field) 33 | 34 | def enterPassword(self, password): 35 | self.sendKeys(password, self._password_field) 36 | 37 | def clickLoginButton(self): 38 | self.elementClick(self._login_button, locatorType="name") 39 | 40 | def login(self, email, password): 41 | self.clickLoginLink() 42 | self.enterEmail(email) 43 | self.enterPassword(password) 44 | self.clickLoginButton() -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/7_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from pages.home.login_page import LoginPage 4 | import unittest 5 | 6 | class LoginTests(unittest.TestCase): 7 | 8 | def test_validLogin(self): 9 | baseURL = "https://letskodeit.teachable.com/" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.implicitly_wait(3) 13 | driver.get(baseURL) 14 | 15 | lp = LoginPage(driver) 16 | lp.login("test@email.com", "abcabc") 17 | 18 | 19 | userIcon = driver.find_element(By.XPATH, ".//*[@id='navbar']//span[text()='User Settings']") 20 | if userIcon is not None: 21 | print("Login Successful") 22 | else: 23 | print("Login Failed") -------------------------------------------------------------------------------- /CODES/S28 - Automation Framework - Part 1/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S28 - Automation Framework - Part 1/Thumbs.db -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/1_custom_logger.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | import logging 3 | 4 | def customLogger(logLevel=logging.DEBUG): 5 | # Gets the name of the class / method from where this method is called 6 | loggerName = inspect.stack()[1][3] 7 | logger = logging.getLogger(loggerName) 8 | # By default, log all messages 9 | logger.setLevel(logging.DEBUG) 10 | 11 | fileHandler = logging.FileHandler("automation.log", mode='a') 12 | fileHandler.setLevel(logLevel) 13 | 14 | formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s: %(message)s', 15 | datefmt='%m/%d/%Y %I:%M:%S %p') 16 | fileHandler.setFormatter(formatter) 17 | logger.addHandler(fileHandler) 18 | 19 | return logger 20 | -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/1_login_page.py: -------------------------------------------------------------------------------- 1 | from base.selenium_driver import SeleniumDriver 2 | import utilities.custom_logger as cl 3 | import logging 4 | 5 | class LoginPage(SeleniumDriver): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _login_link = "Login" 15 | _email_field = "user_email" 16 | _password_field = "user_password" 17 | _login_button = "commit" 18 | 19 | def clickLoginLink(self): 20 | self.elementClick(self._login_link, locatorType="link") 21 | 22 | def enterEmail(self, email): 23 | self.sendKeys(email, self._email_field) 24 | 25 | def enterPassword(self, password): 26 | self.sendKeys(password, self._password_field) 27 | 28 | def clickLoginButton(self): 29 | self.elementClick(self._login_button, locatorType="name") 30 | 31 | def login(self, email, password): 32 | self.clickLoginLink() 33 | self.enterEmail(email) 34 | self.enterPassword(password) 35 | self.clickLoginButton() -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/1_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from pages.home.login_page import LoginPage 4 | import unittest 5 | 6 | class LoginTests(unittest.TestCase): 7 | 8 | def test_validLogin(self): 9 | baseURL = "https://letskodeit.teachable.com/" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.implicitly_wait(3) 13 | driver.get(baseURL) 14 | 15 | lp = LoginPage(driver) 16 | lp.login("test@email.com", "abcabc") 17 | 18 | 19 | userIcon = driver.find_element(By.XPATH, ".//*[@id='navbar']//span[text()='User Settings']") 20 | if userIcon is not None: 21 | print("Login Successful") 22 | else: 23 | print("Login Failed") 24 | driver.quit() -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/2_login_page.py: -------------------------------------------------------------------------------- 1 | from base.selenium_driver import SeleniumDriver 2 | import utilities.custom_logger as cl 3 | import logging 4 | 5 | class LoginPage(SeleniumDriver): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _login_link = "Login" 15 | _email_field = "user_email" 16 | _password_field = "user_password" 17 | _login_button = "commit" 18 | 19 | def clickLoginLink(self): 20 | self.elementClick(self._login_link, locatorType="link") 21 | 22 | def enterEmail(self, email): 23 | self.sendKeys(email, self._email_field) 24 | 25 | def enterPassword(self, password): 26 | self.sendKeys(password, self._password_field) 27 | 28 | def clickLoginButton(self): 29 | self.elementClick(self._login_button, locatorType="name") 30 | 31 | def login(self, email, password): 32 | self.clickLoginLink() 33 | self.enterEmail(email) 34 | self.enterPassword(password) 35 | self.clickLoginButton() 36 | 37 | def verifyLoginSuccessful(self): 38 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 39 | locatorType="xpath") 40 | return result 41 | 42 | def verifyLoginFailed(self): 43 | print("Test") 44 | -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/2_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from pages.home.login_page import LoginPage 3 | import unittest 4 | import pytest 5 | 6 | class LoginTests(unittest.TestCase): 7 | 8 | def test_validLogin(self): 9 | baseURL = "https://letskodeit.teachable.com/" 10 | driver = webdriver.Firefox() 11 | driver.maximize_window() 12 | driver.implicitly_wait(3) 13 | driver.get(baseURL) 14 | 15 | lp = LoginPage(driver) 16 | lp.login("test@email.com", "abcabc") 17 | result = self.lp.verifyLoginSuccessful() 18 | assert result == True 19 | self.driver.quit() -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/3_login_page.py: -------------------------------------------------------------------------------- 1 | from base.selenium_driver import SeleniumDriver 2 | import utilities.custom_logger as cl 3 | import logging 4 | 5 | class LoginPage(SeleniumDriver): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _login_link = "Login" 15 | _email_field = "user_email" 16 | _password_field = "user_password" 17 | _login_button = "commit" 18 | 19 | def clickLoginLink(self): 20 | self.elementClick(self._login_link, locatorType="link") 21 | 22 | def enterEmail(self, email): 23 | self.sendKeys(email, self._email_field) 24 | 25 | def enterPassword(self, password): 26 | self.sendKeys(password, self._password_field) 27 | 28 | def clickLoginButton(self): 29 | self.elementClick(self._login_button, locatorType="name") 30 | 31 | def login(self, email="", password=""): 32 | self.clickLoginLink() 33 | self.enterEmail(email) 34 | self.enterPassword(password) 35 | self.clickLoginButton() 36 | 37 | def verifyLoginSuccessful(self): 38 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 39 | locatorType="xpath") 40 | return result 41 | 42 | def verifyLoginFailed(self): 43 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 44 | locatorType="xpath") 45 | return result 46 | 47 | 48 | -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/3_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from pages.home.login_page import LoginPage 3 | import unittest 4 | import pytest 5 | 6 | class LoginTests(unittest.TestCase): 7 | baseURL = "https://letskodeit.teachable.com/" 8 | driver = webdriver.Firefox() 9 | driver.maximize_window() 10 | driver.implicitly_wait(3) 11 | lp = LoginPage(driver) 12 | 13 | @pytest.mark.run(order=2) 14 | def test_validLogin(self): 15 | self.lp.login("test@email.com", "abcabc") 16 | result = self.lp.verifyLoginSuccessful() 17 | assert result == True 18 | self.driver.quit() 19 | 20 | @pytest.mark.run(order=1) 21 | def test_invalidLogin(self): 22 | self.driver.get(self.baseURL) 23 | self.lp.login("test@email.com", "abcabcabc") 24 | result = self.lp.verifyLoginFailed() 25 | assert result == True -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/4_conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from selenium import webdriver 3 | 4 | @pytest.yield_fixture() 5 | def setUp(): 6 | print("Running method level setUp") 7 | yield 8 | print("Running method level tearDown") 9 | 10 | 11 | @pytest.yield_fixture(scope="class") 12 | def oneTimeSetUp(request, browser): 13 | print("Running one time setUp") 14 | if browser == 'firefox': 15 | baseURL = "https://letskodeit.teachable.com/" 16 | driver = webdriver.Firefox() 17 | driver.maximize_window() 18 | driver.implicitly_wait(3) 19 | driver.get(baseURL) 20 | print("Running tests on FF") 21 | else: 22 | baseURL = "https://letskodeit.teachable.com/" 23 | driver = webdriver.Chrome() 24 | driver.get(baseURL) 25 | print("Running tests on chrome") 26 | 27 | if request.cls is not None: 28 | request.cls.driver = driver 29 | 30 | yield driver 31 | driver.quit() 32 | print("Running one time tearDown") 33 | 34 | def pytest_addoption(parser): 35 | parser.addoption("--browser") 36 | parser.addoption("--osType", help="Type of operating system") 37 | 38 | @pytest.fixture(scope="session") 39 | def browser(request): 40 | return request.config.getoption("--browser") 41 | 42 | @pytest.fixture(scope="session") 43 | def osType(request): 44 | return request.config.getoption("--osType") -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/4_login_page.py: -------------------------------------------------------------------------------- 1 | from base.selenium_driver import SeleniumDriver 2 | import utilities.custom_logger as cl 3 | import logging 4 | 5 | class LoginPage(SeleniumDriver): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _login_link = "Login" 15 | _email_field = "user_email" 16 | _password_field = "user_password" 17 | _login_button = "commit" 18 | 19 | def clickLoginLink(self): 20 | self.elementClick(self._login_link, locatorType="link") 21 | 22 | def enterEmail(self, email): 23 | self.sendKeys(email, self._email_field) 24 | 25 | def enterPassword(self, password): 26 | self.sendKeys(password, self._password_field) 27 | 28 | def clickLoginButton(self): 29 | self.elementClick(self._login_button, locatorType="name") 30 | 31 | def login(self, email="", password=""): 32 | self.clickLoginLink() 33 | self.enterEmail(email) 34 | self.enterPassword(password) 35 | self.clickLoginButton() 36 | 37 | def verifyLoginSuccessful(self): 38 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 39 | locatorType="xpath") 40 | return result 41 | 42 | def verifyLoginFailed(self): 43 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 44 | locatorType="xpath") 45 | return result 46 | 47 | 48 | -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/4_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from pages.home.login_page import LoginPage 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class LoginTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def classSetup(self, oneTimeSetUp): 11 | self.lp = LoginPage(self.driver) 12 | 13 | 14 | @pytest.mark.run(order=2) 15 | def test_validLogin(self): 16 | self.lp.login("test@email.com", "abcabc") 17 | result = self.lp.verifyLoginSuccessful() 18 | assert result == True 19 | 20 | @pytest.mark.run(order=1) 21 | def test_invalidLogin(self): 22 | self.lp.login("test@email.com", "abcabcabc") 23 | result = self.lp.verifyLoginFailed() 24 | assert result == True -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/5_conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from selenium import webdriver 3 | from base.webdriverfactory import WebDriverFactory 4 | 5 | @pytest.yield_fixture() 6 | def setUp(): 7 | print("Running method level setUp") 8 | yield 9 | print("Running method level tearDown") 10 | 11 | 12 | @pytest.yield_fixture(scope="class") 13 | def oneTimeSetUp(request, browser): 14 | print("Running one time setUp") 15 | wdf = WebDriverFactory(browser) 16 | driver = wdf.getWebDriverInstance() 17 | 18 | if request.cls is not None: 19 | request.cls.driver = driver 20 | 21 | yield driver 22 | driver.quit() 23 | print("Running one time tearDown") 24 | 25 | def pytest_addoption(parser): 26 | parser.addoption("--browser") 27 | parser.addoption("--osType", help="Type of operating system") 28 | 29 | @pytest.fixture(scope="session") 30 | def browser(request): 31 | return request.config.getoption("--browser") 32 | 33 | @pytest.fixture(scope="session") 34 | def osType(request): 35 | return request.config.getoption("--osType") -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/5_login_page.py: -------------------------------------------------------------------------------- 1 | from base.selenium_driver import SeleniumDriver 2 | import utilities.custom_logger as cl 3 | import logging 4 | 5 | class LoginPage(SeleniumDriver): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _login_link = "Login" 15 | _email_field = "user_email" 16 | _password_field = "user_password" 17 | _login_button = "commit" 18 | 19 | def clickLoginLink(self): 20 | self.elementClick(self._login_link, locatorType="link") 21 | 22 | def enterEmail(self, email): 23 | self.sendKeys(email, self._email_field) 24 | 25 | def enterPassword(self, password): 26 | self.sendKeys(password, self._password_field) 27 | 28 | def clickLoginButton(self): 29 | self.elementClick(self._login_button, locatorType="name") 30 | 31 | def login(self, email="", password=""): 32 | self.clickLoginLink() 33 | self.enterEmail(email) 34 | self.enterPassword(password) 35 | self.clickLoginButton() 36 | 37 | def verifyLoginSuccessful(self): 38 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 39 | locatorType="xpath") 40 | return result 41 | 42 | def verifyLoginFailed(self): 43 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 44 | locatorType="xpath") 45 | return result 46 | 47 | 48 | -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/5_login_tests.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from pages.home.login_page import LoginPage 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class LoginTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def classSetup(self, oneTimeSetUp): 11 | self.lp = LoginPage(self.driver) 12 | 13 | 14 | @pytest.mark.run(order=2) 15 | def test_validLogin(self): 16 | self.lp.login("test@email.com", "abcabc") 17 | result = self.lp.verifyLoginSuccessful() 18 | assert result == True 19 | 20 | @pytest.mark.run(order=1) 21 | def test_invalidLogin(self): 22 | self.lp.login("test@email.com", "abcabcabc") 23 | result = self.lp.verifyLoginFailed() 24 | assert result == True -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/5_webdriverfactory.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package base 3 | 4 | WebDriver Factory class implementation 5 | It creates a webdriver instance based on browser configurations 6 | 7 | Example: 8 | wdf = WebDriverFactory(browser) 9 | wdf.getWebDriverInstance() 10 | """ 11 | import traceback 12 | from selenium import webdriver 13 | 14 | class WebDriverFactory(): 15 | 16 | def __init__(self, browser): 17 | """ 18 | Inits WebDriverFactory class 19 | 20 | Returns: 21 | None 22 | """ 23 | self.browser = browser 24 | """ 25 | Set chrome driver and iexplorer environment based on OS 26 | 27 | chromedriver = "C:/.../chromedriver.exe" 28 | os.environ["webdriver.chrome.driver"] = chromedriver 29 | self.driver = webdriver.Chrome(chromedriver) 30 | 31 | PREFERRED: Set the path on the machine where browser will be executed 32 | """ 33 | 34 | def getWebDriverInstance(self): 35 | """ 36 | Get WebDriver Instance based on the browser configuration 37 | 38 | Returns: 39 | 'WebDriver Instance' 40 | """ 41 | baseURL = "https://letskodeit.teachable.com/" 42 | if self.browser == "iexplorer": 43 | # Set ie driver 44 | driver = webdriver.Ie() 45 | elif self.browser == "firefox": 46 | driver = webdriver.Firefox() 47 | elif self.browser == "chrome": 48 | # Set chrome driver 49 | driver = webdriver.Chrome() 50 | else: 51 | driver = webdriver.Firefox() 52 | # Setting Driver Implicit Time out for An Element 53 | driver.implicitly_wait(3) 54 | # Maximize the window 55 | driver.maximize_window() 56 | # Loading browser with App URL 57 | driver.get(baseURL) 58 | return driver -------------------------------------------------------------------------------- /CODES/S29 - Automation Framework - Part 2/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S29 - Automation Framework - Part 2/Thumbs.db -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/10-string-methods2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Examples to show available string methods in python 3 | """ 4 | 5 | # Replace Method 6 | a = "1abc2abc3abc4abc" 7 | print(a.replace('abc', 'ABC')) 8 | 9 | # Sub-Strings 10 | # starting index is inclusive 11 | # Ending index is exclusive 12 | sub = a[1:6] 13 | step = a[1:6:2] 14 | 15 | print("****************") 16 | 17 | print(sub) 18 | print(step) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/12-strings-formatting.py: -------------------------------------------------------------------------------- 1 | """ 2 | Examples to show how string formatting works in python 3 | """ 4 | 5 | city = "nyc" 6 | event = "show" 7 | 8 | print("Welcome to " + city + " and enjoy the " + event) 9 | print("Welcome to %s" % city) 10 | print("Welcome to %s and enjoy the %s" % (city, event)) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/2-variables.py: -------------------------------------------------------------------------------- 1 | """ 2 | table 3 | object reference count 4 | """ 5 | 6 | a="nyc" 7 | b="nyc" 8 | 9 | print(a) 10 | 11 | a=123 12 | 13 | print(a) 14 | print(b) 15 | 16 | b=456 17 | print(b) 18 | 19 | c='nyc' 20 | d=c 21 | 22 | print(c==d) 23 | print(d is c) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/3-Variables Rules.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S3 - Understanding Variables And Data Type/3-Variables Rules.docx -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/3-Variables Rules.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S3 - Understanding Variables And Data Type/3-Variables Rules.pdf -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/3-variables-rules.py: -------------------------------------------------------------------------------- 1 | """ 2 | variables rules 3 | """ 4 | 5 | import keyword 6 | print(keyword.kwlist) 7 | 8 | a = b = c = 10 9 | print(a) 10 | print(b) 11 | print(c) 12 | 13 | x, y, z = 10, 20, 30 14 | print(x) 15 | print(y) 16 | print(z) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/4-numbers.py: -------------------------------------------------------------------------------- 1 | int_num = 10 2 | float_num = 20.0 3 | 4 | print(int_num) 5 | print(float_num) 6 | 7 | a = 10 8 | b = 20 9 | 10 | print("*******************") 11 | 12 | add = a + b 13 | print(add) 14 | 15 | sub = b - a 16 | print(sub) 17 | 18 | multi = a * b 19 | print(multi) 20 | 21 | div_mychoice = b / a 22 | print(div_mychoice) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/5-numbers-operations.py: -------------------------------------------------------------------------------- 1 | # This is a one line comment 2 | 3 | # Exponentiation 4 | # 10 * 10 ... 20 5 | exponents = 10 ** 20 6 | print(exponents) 7 | 8 | 9 | """ 10 | This is a multi-line comment 11 | Modulo - It returns the remainder 12 | """ 13 | 14 | remainder = 11 % 3 15 | print(remainder) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/7-boolean.py: -------------------------------------------------------------------------------- 1 | """ 2 | Examples to show how boolean works in python 3 | """ 4 | 5 | a = True 6 | b = False 7 | 8 | print(a) 9 | print(b) 10 | 11 | print("**************************") 12 | print(bool(0)) 13 | print(bool(1)) 14 | print(bool(2)) 15 | 16 | c = "" 17 | print(bool(c)) 18 | 19 | c = "Some Value" 20 | print(bool(c)) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/8-strings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Examples to show how strings works in python 3 | 4 | Sequence of characters 5 | Contains a-z, 0-9, @ 6 | In double or single quotes 7 | """ 8 | 9 | a = "This is a simple string" 10 | b = 'Using single quotes' 11 | 12 | print(a) 13 | print(b) 14 | 15 | c = "Need to use 'quotes' inside a string" 16 | print(c) 17 | 18 | d = "Another way to handle \"quotes\"" 19 | print(d) 20 | 21 | a = "This is a single\ 22 | string" 23 | print(a) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/9-string-methods1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Examples to show available string methods in python 3 | """ 4 | 5 | # Accessing characters in a string 6 | # index starts from zero 7 | first = "nyc"[0] 8 | city = "sfo" 9 | print(first) 10 | ft = city[0] 11 | print(ft) 12 | 13 | 14 | """ 15 | len() 16 | lower() 17 | upper() 18 | str() 19 | """ 20 | 21 | stri = "This Is a Mixed Case" 22 | print(stri.lower()) 23 | print(stri.upper()) 24 | print(len(stri)) 25 | 26 | print(stri + str(2)) 27 | 28 | """ 29 | Concatenation 30 | """ 31 | print("Hello " + " " + " World !!!") 32 | print(first + " " + city) -------------------------------------------------------------------------------- /CODES/S3 - Understanding Variables And Data Type/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S3 - Understanding Variables And Data Type/Thumbs.db -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/1_login_page.py: -------------------------------------------------------------------------------- 1 | from base.selenium_driver import SeleniumDriver 2 | import utilities.custom_logger as cl 3 | import logging 4 | 5 | class LoginPage(SeleniumDriver): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _login_link = "Login" 15 | _email_field = "user_email" 16 | _password_field = "user_password" 17 | _login_button = "commit" 18 | 19 | def clickLoginLink(self): 20 | self.elementClick(self._login_link, locatorType="link") 21 | 22 | def enterEmail(self, email): 23 | self.sendKeys(email, self._email_field) 24 | 25 | def enterPassword(self, password): 26 | self.sendKeys(password, self._password_field) 27 | 28 | def clickLoginButton(self): 29 | self.elementClick(self._login_button, locatorType="name") 30 | 31 | def login(self, email="", password=""): 32 | self.clickLoginLink() 33 | self.enterEmail(email) 34 | self.enterPassword(password) 35 | self.clickLoginButton() 36 | 37 | def verifyLoginSuccessful(self): 38 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 39 | locatorType="xpath") 40 | return result 41 | 42 | def verifyLoginFailed(self): 43 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 44 | locatorType="xpath") 45 | return result 46 | 47 | def verifyTitle(self): 48 | if "Google" in self.getTitle(): 49 | return True 50 | else: 51 | return False -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/1_login_tests.py: -------------------------------------------------------------------------------- 1 | from pages.home.login_page import LoginPage 2 | import unittest 3 | import pytest 4 | 5 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 6 | class LoginTests(unittest.TestCase): 7 | 8 | @pytest.fixture(autouse=True) 9 | def classSetup(self, oneTimeSetUp): 10 | self.lp = LoginPage(self.driver) 11 | 12 | 13 | # Need to verify two verification points 14 | # 1 fails, code will not go to the next verification point 15 | # If assert fails, it stops current test execution and 16 | # moves to the next test method 17 | @pytest.mark.run(order=2) 18 | def test_validLogin(self): 19 | self.lp.login("test@email.com", "abcabc") 20 | result1 = self.lp.verifyTitle() 21 | assert result1 == True 22 | result2 = self.lp.verifyLoginSuccessful() 23 | assert result2 == True 24 | 25 | @pytest.mark.run(order=1) 26 | def test_invalidLogin(self): 27 | self.lp.login("test@email.com", "abcabcabc") 28 | result = self.lp.verifyLoginFailed() 29 | assert result == True -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/2_teststatus.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package utilities 3 | 4 | CheckPoint class implementation 5 | It provides functionality to assert the result 6 | 7 | Example: 8 | self.check_point.markFinal("Test Name", result, "Message") 9 | """ 10 | import utilities.custom_logger as cl 11 | import logging 12 | from base.selenium_driver import SeleniumDriver 13 | 14 | class TestStatus(SeleniumDriver): 15 | 16 | log = cl.customLogger(logging.INFO) 17 | 18 | def __init__(self, driver): 19 | """ 20 | Inits CheckPoint class 21 | """ 22 | super(TestStatus, self).__init__(driver) 23 | self.resultList = [] 24 | 25 | def setResult(self, result, resultMessage): 26 | try: 27 | if result is not None: 28 | if result: 29 | self.resultList.append("PASS") 30 | self.log.info("### VERIFICATION SUCCESSFUL :: + " + resultMessage) 31 | else: 32 | self.resultList.append("FAIL") 33 | self.log.info("### VERIFICATION FAILED :: + " + resultMessage) 34 | else: 35 | self.resultList.append("FAIL") 36 | self.log.info("### VERIFICATION FAILED :: + " + resultMessage) 37 | except: 38 | self.resultList.append("FAIL") 39 | self.log.info("### Exception Occurred !!!") 40 | 41 | def mark(self, result, resultMessage): 42 | """ 43 | Mark the result of the verification point in a test case 44 | """ 45 | self.setResult(result, resultMessage) 46 | 47 | def markFinal(self, testName, result, resultMessage): 48 | """ 49 | Mark the final result of the verification point in a test case 50 | This needs to be called at least once in a test case 51 | This should be final test status of the test case 52 | """ 53 | print() -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/3_login_tests.py: -------------------------------------------------------------------------------- 1 | from pages.home.login_page import LoginPage 2 | from utilities.teststatus import TestStatus 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class LoginTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def classSetup(self, oneTimeSetUp): 11 | self.lp = LoginPage(self.driver) 12 | self.ts = TestStatus(self.driver) 13 | 14 | @pytest.mark.run(order=2) 15 | def test_validLogin(self): 16 | self.lp.login("test@email.com", "abcabc") 17 | result1 = self.lp.verifyTitle() 18 | self.ts.mark(result1, "Title Verified") 19 | result2 = self.lp.verifyLoginSuccessful() 20 | self.ts.markFinal("test_validLogin", result2, "Login was successful") 21 | 22 | @pytest.mark.run(order=1) 23 | def test_invalidLogin(self): 24 | self.lp.login("test@email.com", "abcabcabc") 25 | result = self.lp.verifyLoginFailed() 26 | assert result == True -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/3_teststatus.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package utilities 3 | 4 | CheckPoint class implementation 5 | It provides functionality to assert the result 6 | 7 | Example: 8 | self.check_point.markFinal("Test Name", result, "Message") 9 | """ 10 | import utilities.custom_logger as cl 11 | import logging 12 | from base.selenium_driver import SeleniumDriver 13 | 14 | class TestStatus(SeleniumDriver): 15 | 16 | log = cl.customLogger(logging.INFO) 17 | 18 | def __init__(self, driver): 19 | """ 20 | Inits CheckPoint class 21 | """ 22 | super(TestStatus, self).__init__(driver) 23 | self.resultList = [] 24 | 25 | def setResult(self, result, resultMessage): 26 | try: 27 | if result is not None: 28 | if result: 29 | self.resultList.append("PASS") 30 | self.log.info("### VERIFICATION SUCCESSFUL :: + " + resultMessage) 31 | else: 32 | self.resultList.append("FAIL") 33 | self.log.error("### VERIFICATION FAILED :: + " + resultMessage) 34 | else: 35 | self.resultList.append("FAIL") 36 | self.log.error("### VERIFICATION FAILED :: + " + resultMessage) 37 | except: 38 | self.resultList.append("FAIL") 39 | self.log.error("### Exception Occurred !!!") 40 | 41 | def mark(self, result, resultMessage): 42 | """ 43 | Mark the result of the verification point in a test case 44 | """ 45 | self.setResult(result, resultMessage) 46 | 47 | def markFinal(self, testName, result, resultMessage): 48 | """ 49 | Mark the final result of the verification point in a test case 50 | This needs to be called at least once in a test case 51 | This should be final test status of the test case 52 | """ 53 | self.setResult(result, resultMessage) 54 | 55 | if "FAIL" in self.resultList: 56 | self.log.error(testName + " ### TEST FAILED") 57 | self.resultList.clear() 58 | assert True == False 59 | else: 60 | self.log.info(testName + " ### TEST SUCCESSFUL") 61 | self.resultList.clear() 62 | assert True == True -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/5_teststatus.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package utilities 3 | 4 | CheckPoint class implementation 5 | It provides functionality to assert the result 6 | 7 | Example: 8 | self.check_point.markFinal("Test Name", result, "Message") 9 | """ 10 | import utilities.custom_logger as cl 11 | import logging 12 | from base.selenium_driver import SeleniumDriver 13 | from traceback import print_stack 14 | 15 | class TestStatus(SeleniumDriver): 16 | 17 | log = cl.customLogger(logging.INFO) 18 | 19 | def __init__(self, driver): 20 | """ 21 | Inits CheckPoint class 22 | """ 23 | super(TestStatus, self).__init__(driver) 24 | self.resultList = [] 25 | 26 | def setResult(self, result, resultMessage): 27 | try: 28 | if result is not None: 29 | if result: 30 | self.resultList.append("PASS") 31 | self.log.info("### VERIFICATION SUCCESSFUL :: + " + resultMessage) 32 | else: 33 | self.resultList.append("FAIL") 34 | self.log.error("### VERIFICATION FAILED :: + " + resultMessage) 35 | self.screenShot(resultMessage) 36 | else: 37 | self.resultList.append("FAIL") 38 | self.log.error("### VERIFICATION FAILED :: + " + resultMessage) 39 | self.screenShot(resultMessage) 40 | except: 41 | self.resultList.append("FAIL") 42 | self.log.error("### Exception Occurred !!!") 43 | self.screenShot(resultMessage) 44 | print_stack() 45 | 46 | def mark(self, result, resultMessage): 47 | """ 48 | Mark the result of the verification point in a test case 49 | """ 50 | self.setResult(result, resultMessage) 51 | 52 | def markFinal(self, testName, result, resultMessage): 53 | """ 54 | Mark the final result of the verification point in a test case 55 | This needs to be called at least once in a test case 56 | This should be final test status of the test case 57 | """ 58 | self.setResult(result, resultMessage) 59 | 60 | if "FAIL" in self.resultList: 61 | self.log.error(testName + " ### TEST FAILED") 62 | self.resultList.clear() 63 | assert True == False 64 | else: 65 | self.log.info(testName + " ### TEST SUCCESSFUL") 66 | self.resultList.clear() 67 | assert True == True -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/6_basepage.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package base 3 | 4 | Base Page class implementation 5 | It implements methods which are common to all the pages throughout the application 6 | 7 | This class needs to be inherited by all the page classes 8 | This should not be used by creating object instances 9 | 10 | Example: 11 | Class LoginPage(BasePage) 12 | """ 13 | from base.selenium_driver import SeleniumDriver 14 | from traceback import print_stack 15 | from utilities.util import Util 16 | 17 | class BasePage(SeleniumDriver): 18 | 19 | def __init__(self, driver): 20 | """ 21 | Inits BasePage class 22 | 23 | Returns: 24 | None 25 | """ 26 | super(BasePage, self).__init__(driver) 27 | self.driver = driver 28 | self.util = Util() 29 | 30 | def verifyPageTitle(self, titleToVerify): 31 | """ 32 | Verify the page Title 33 | 34 | Parameters: 35 | titleToVerify: Title on the page that needs to be verified 36 | """ 37 | try: 38 | actualTitle = self.getTitle() 39 | return self.util.verifyTextContains(actualTitle, titleToVerify) 40 | except: 41 | self.log.error("Failed to get page title") 42 | print_stack() 43 | return False -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/7_basepage.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package base 3 | 4 | Base Page class implementation 5 | It implements methods which are common to all the pages throughout the application 6 | 7 | This class needs to be inherited by all the page classes 8 | This should not be used by creating object instances 9 | 10 | Example: 11 | Class LoginPage(BasePage) 12 | """ 13 | from base.selenium_driver import SeleniumDriver 14 | from traceback import print_stack 15 | from utilities.util import Util 16 | 17 | class BasePage(SeleniumDriver): 18 | 19 | def __init__(self, driver): 20 | """ 21 | Inits BasePage class 22 | 23 | Returns: 24 | None 25 | """ 26 | super(BasePage, self).__init__(driver) 27 | self.driver = driver 28 | self.util = Util() 29 | 30 | def verifyPageTitle(self, titleToVerify): 31 | """ 32 | Verify the page Title 33 | 34 | Parameters: 35 | titleToVerify: Title on the page that needs to be verified 36 | """ 37 | try: 38 | actualTitle = self.getTitle() 39 | return self.util.verifyTextContains(actualTitle, titleToVerify) 40 | except: 41 | self.log.error("Failed to get page title") 42 | print_stack() 43 | return False -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/7_login_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class LoginPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _login_link = "Login" 15 | _email_field = "user_email" 16 | _password_field = "user_password" 17 | _login_button = "commit" 18 | 19 | def clickLoginLink(self): 20 | self.elementClick(self._login_link, locatorType="link") 21 | 22 | def enterEmail(self, email): 23 | self.sendKeys(email, self._email_field) 24 | 25 | def enterPassword(self, password): 26 | self.sendKeys(password, self._password_field) 27 | 28 | def clickLoginButton(self): 29 | self.elementClick(self._login_button, locatorType="name") 30 | 31 | def login(self, email="", password=""): 32 | self.clickLoginLink() 33 | self.enterEmail(email) 34 | self.enterPassword(password) 35 | self.clickLoginButton() 36 | 37 | def verifyLoginSuccessful(self): 38 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 39 | locatorType="xpath") 40 | return result 41 | 42 | def verifyLoginFailed(self): 43 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 44 | locatorType="xpath") 45 | return result 46 | 47 | def verifyLoginTitle(self): 48 | return self.verifyPageTitle("Google") -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/7_login_tests.py: -------------------------------------------------------------------------------- 1 | from pages.home.login_page import LoginPage 2 | from utilities.teststatus import TestStatus 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class LoginTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def classSetup(self, oneTimeSetUp): 11 | self.lp = LoginPage(self.driver) 12 | self.ts = TestStatus(self.driver) 13 | 14 | @pytest.mark.run(order=2) 15 | def test_validLogin(self): 16 | self.lp.login("test@email.com", "abcabc") 17 | result1 = self.lp.verifyLoginTitle() 18 | self.ts.mark(result1, "Title Verification") 19 | result2 = self.lp.verifyLoginSuccessful() 20 | self.ts.markFinal("test_validLogin", result2, "Login Verification") 21 | 22 | @pytest.mark.run(order=1) 23 | def test_invalidLogin(self): 24 | self.lp.login("test@email.com", "abcabcabc") 25 | result = self.lp.verifyLoginFailed() 26 | assert result == True -------------------------------------------------------------------------------- /CODES/S30 - Automation Framework - Part 3/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S30 - Automation Framework - Part 3/Thumbs.db -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/1_conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from base.webdriverfactory import WebDriverFactory 3 | from pages.home.login_page import LoginPage 4 | 5 | @pytest.yield_fixture() 6 | def setUp(): 7 | print("Running method level setUp") 8 | yield 9 | print("Running method level tearDown") 10 | 11 | 12 | @pytest.yield_fixture(scope="class") 13 | def oneTimeSetUp(request, browser): 14 | print("Running one time setUp") 15 | wdf = WebDriverFactory(browser) 16 | driver = wdf.getWebDriverInstance() 17 | lp = LoginPage(driver) 18 | lp.login("test@email.com", "abcabc") 19 | 20 | if request.cls is not None: 21 | request.cls.driver = driver 22 | yield driver 23 | driver.quit() 24 | print("Running one time tearDown") 25 | 26 | def pytest_addoption(parser): 27 | parser.addoption("--browser") 28 | parser.addoption("--osType", help="Type of operating system") 29 | 30 | @pytest.fixture(scope="session") 31 | def browser(request): 32 | return request.config.getoption("--browser") 33 | 34 | @pytest.fixture(scope="session") 35 | def osType(request): 36 | return request.config.getoption("--osType") -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/3_register_courses_pages.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class RegisterCoursesPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | ################ 14 | ### Locators ### 15 | ################ 16 | _search_box = "search-courses" 17 | _course = "//div[contains(@class,'course-listing-title') and contains(text(),'{0}')]" 18 | _all_courses = "course-listing-title" 19 | _enroll_button = "enroll-button-top" 20 | _cc_num = "cc_field" 21 | _cc_exp = "cc-exp" 22 | _cc_cvv = "cc_cvc" 23 | _submit_enroll = "//div[@id='new_card']//button[contains(text(),'Enroll in Course')]" 24 | _enroll_error_message = "//div[@id='new_card']//div[contains(text(),'The card number is not a valid credit card number.')]" 25 | 26 | ############################ 27 | ### Element Interactions ### 28 | ############################ 29 | 30 | def enterCourseName(self, name): 31 | print() 32 | 33 | def selectCourseToEnroll(self, fullCourseName): 34 | print() 35 | 36 | def clickOnEnrollButton(self): 37 | print() 38 | 39 | def enterCardNum(self, num): 40 | print() 41 | 42 | def enterCardExp(self, exp): 43 | print() 44 | 45 | def enterCardCVV(self, cvv): 46 | print() 47 | 48 | def clickEnrollSubmitButton(self): 49 | print() 50 | 51 | def enterCreditCardInformation(self, num, exp, cvv): 52 | print() 53 | 54 | def enrollCourse(self, num="", exp="", cvv=""): 55 | print() 56 | 57 | def verifyEnrollFailed(self): 58 | print() -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/4_register_courses_pages.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class RegisterCoursesPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | ################ 14 | ### Locators ### 15 | ################ 16 | _search_box = "search-courses" 17 | _course = "//div[contains(@class,'course-listing-title') and contains(text(),'{0}')]" 18 | _all_courses = "course-listing-title" 19 | _enroll_button = "enroll-button-top" 20 | _cc_num = "cc_field" 21 | _cc_exp = "cc-exp" 22 | _cc_cvv = "cc_cvc" 23 | _submit_enroll = "//div[@id='new_card']//button[contains(text(),'Enroll in Course')]" 24 | _enroll_error_message = "//div[@id='new_card']//div[contains(text(),'The card number is not a valid credit card number.')]" 25 | 26 | ############################ 27 | ### Element Interactions ### 28 | ############################ 29 | 30 | def enterCourseName(self, name): 31 | self.sendKeys(name, locator=self._search_box) 32 | 33 | def selectCourseToEnroll(self, fullCourseName): 34 | self.elementClick(locator=self._course.format(fullCourseName), locatorType="xpath") 35 | 36 | def clickOnEnrollButton(self): 37 | self.elementClick(locator=self._enroll_button) 38 | 39 | def enterCardNum(self, num): 40 | self.sendKeys(num, locator=self._cc_num) 41 | 42 | def enterCardExp(self, exp): 43 | self.sendKeys(exp, locator=self._cc_exp) 44 | 45 | def enterCardCVV(self, cvv): 46 | self.sendKeys(cvv, locator=self._cc_cvv) 47 | 48 | def clickEnrollSubmitButton(self): 49 | self.sendKeys(self._submit_enroll, locator="xpath") 50 | 51 | def enterCreditCardInformation(self, num, exp, cvv): 52 | self.enterCardNum(num) 53 | self.enterCardExp(exp) 54 | self.enterCardCVV(cvv) 55 | 56 | def enrollCourse(self, num="", exp="", cvv=""): 57 | self.clickOnEnrollButton() 58 | self.webScroll(direction="down") 59 | self.enterCreditCardInformation(num, exp, cvv) 60 | self.clickEnrollSubmitButton() 61 | 62 | def verifyEnrollFailed(self): 63 | messageElement = self.waitForElement(self._enroll_error_message, locatorType="xpath") 64 | result = self.isElementDisplayed(element=messageElement) 65 | return result 66 | -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/5_register_courses_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class RegisterCoursesPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | ################ 14 | ### Locators ### 15 | ################ 16 | _search_box = "search-courses" 17 | _course = "//div[contains(@class,'course-listing-title') and contains(text(),'{0}')]" 18 | _all_courses = "course-listing-title" 19 | _enroll_button = "enroll-button-top" 20 | _cc_num = "cc_field" 21 | _cc_exp = "cc-exp" 22 | _cc_cvv = "cc_cvc" 23 | _submit_enroll = "//div[@id='new_card']//button[contains(text(),'Enroll in Course')]" 24 | _enroll_error_message = "//div[@id='new_card']//div[contains(text(),'The card number is not a valid credit card number.')]" 25 | 26 | ############################ 27 | ### Element Interactions ### 28 | ############################ 29 | 30 | def enterCourseName(self, name): 31 | self.sendKeys(name, locator=self._search_box) 32 | 33 | def selectCourseToEnroll(self, fullCourseName): 34 | self.elementClick(locator=self._course.format(fullCourseName), locatorType="xpath") 35 | 36 | def clickOnEnrollButton(self): 37 | self.elementClick(locator=self._enroll_button) 38 | 39 | def enterCardNum(self, num): 40 | self.sendKeys(num, locator=self._cc_num) 41 | 42 | def enterCardExp(self, exp): 43 | self.sendKeys(exp, locator=self._cc_exp) 44 | 45 | def enterCardCVV(self, cvv): 46 | self.sendKeys(cvv, locator=self._cc_cvv) 47 | 48 | def clickEnrollSubmitButton(self): 49 | self.elementClick(locator=self._submit_enroll, locatorType="xpath") 50 | 51 | def enterCreditCardInformation(self, num, exp, cvv): 52 | self.enterCardNum(num) 53 | self.enterCardExp(exp) 54 | self.enterCardCVV(cvv) 55 | 56 | def enrollCourse(self, num="", exp="", cvv=""): 57 | self.clickOnEnrollButton() 58 | self.webScroll(direction="down") 59 | self.enterCreditCardInformation(num, exp, cvv) 60 | self.clickEnrollSubmitButton() 61 | 62 | def verifyEnrollFailed(self): 63 | messageElement = self.waitForElement(self._enroll_error_message, locatorType="xpath") 64 | result = self.isElementDisplayed(element=messageElement) 65 | return result 66 | -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/5_register_courses_tests.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from utilities.teststatus import TestStatus 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class RegisterCoursesTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def objectSetup(self, oneTimeSetUp): 11 | self.courses = RegisterCoursesPage(self.driver) 12 | self.ts = TestStatus(self.driver) 13 | 14 | @pytest.mark.run(order=1) 15 | def test_invalidEnrollment(self): 16 | self.courses.enterCourseName("JavaScript") 17 | self.courses.selectCourseToEnroll("JavaScript for beginners") 18 | self.courses.enrollCourse(num="10", exp="1220", cvv="10") 19 | result = self.courses.verifyEnrollFailed() 20 | self.ts.markFinal("test_invalidEnrollment", result, 21 | "Enrollment Failed Verification") -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/6_register_courses_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class RegisterCoursesPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | ################ 14 | ### Locators ### 15 | ################ 16 | _search_box = "search-courses" 17 | _search_course_icon = "search-course-button" 18 | _course = "//div[contains(@class,'course-listing-title') and contains(text(),'{0}')]" 19 | _all_courses = "course-listing-title" 20 | _enroll_button = "enroll-button-top" 21 | _cc_num = "//input[@aria-label='Credit or debit card number']" 22 | _cc_exp = "exp-date" 23 | _cc_cvv = "cvc" 24 | _zip = "postal" 25 | _agree_to_terms_checkbox = "agreed_to_terms_checkbox" 26 | _submit_enroll = "//button[@id='confirm-purchase']/parent::div" 27 | 28 | ############################ 29 | ### Element Interactions ### 30 | ############################ 31 | 32 | def enterCourseName(self, name): 33 | self.sendKeys(name, locator=self._search_box) 34 | self.elementClick(locator=self._search_course_icon) 35 | 36 | def selectCourseToEnroll(self, fullCourseName): 37 | self.elementClick(locator=self._course.format(fullCourseName), locatorType="xpath") 38 | 39 | def clickOnEnrollButton(self): 40 | self.elementClick(locator=self._enroll_button) 41 | 42 | def enterCardNum(self, num): 43 | self.switchToFrame(name="__privateStripeFrame4") 44 | self.sendKeys(num, locator=self._cc_num, locatorType="xpath") 45 | self.switchToDefaultContent() 46 | 47 | def enterCardExp(self, exp): 48 | self.switchToFrame(name="__privateStripeFrame5") 49 | self.sendKeys(exp, locator=self._cc_exp, locatorType="name") 50 | self.switchToDefaultContent() 51 | 52 | def enterCardCVV(self, cvv): 53 | self.switchToFrame(name="__privateStripeFrame6") 54 | self.sendKeys(cvv, locator=self._cc_cvv, locatorType="name") 55 | self.switchToDefaultContent() 56 | 57 | def enterZip(self, zip): 58 | self.switchToFrame(name="__privateStripeFrame7") 59 | self.sendKeys(zip, locator=self._zip, locatorType="name") 60 | self.switchToDefaultContent() 61 | 62 | def clickAgreeToTermsCheckbox(self): 63 | self.elementClick(locator=self._agree_to_terms_checkbox) 64 | 65 | def clickEnrollSubmitButton(self): 66 | self.elementClick(locator=self._submit_enroll, locatorType="xpath") 67 | 68 | def enterCreditCardInformation(self, num, exp, cvv, zip): 69 | self.enterCardNum(num) 70 | self.enterCardExp(exp) 71 | self.enterCardCVV(cvv) 72 | self.enterZip(zip) 73 | 74 | def enrollCourse(self, num="", exp="", cvv="", zip=""): 75 | self.clickOnEnrollButton() 76 | self.webScroll(direction="down") 77 | self.enterCreditCardInformation(num, exp, cvv, zip) 78 | self.clickAgreeToTermsCheckbox() 79 | 80 | def verifyEnrollFailed(self): 81 | result = self.isEnabled(locator=self._submit_enroll, locatorType="xpath", 82 | info="Enroll Button") 83 | return not result -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/6_register_courses_tests.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from utilities.teststatus import TestStatus 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class RegisterCoursesTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def objectSetup(self, oneTimeSetUp): 11 | self.courses = RegisterCoursesPage(self.driver) 12 | self.ts = TestStatus(self.driver) 13 | 14 | @pytest.mark.run(order=1) 15 | def test_invalidEnrollment(self): 16 | self.courses.enterCourseName("JavaScript") 17 | self.courses.selectCourseToEnroll("JavaScript for beginners") 18 | self.courses.enrollCourse(num="1234 5678 9012 3456", exp="1220", cvv="444", zip="12345") 19 | result = self.courses.verifyEnrollFailed() 20 | self.ts.markFinal("test_invalidEnrollment", result, 21 | "Enrollment Failed Verification") -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/7_register_courses_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class RegisterCoursesPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | ################ 14 | ### Locators ### 15 | ################ 16 | _search_box = "search-courses" 17 | _search_course_icon = "search-course-button" 18 | _course = "//div[contains(@class,'course-listing-title') and contains(text(),'{0}')]" 19 | _all_courses = "course-listing-title" 20 | _enroll_button = "enroll-button-top" 21 | _cc_num = "//input[@aria-label='Credit or debit card number']" 22 | _cc_exp = "exp-date" 23 | _cc_cvv = "cvc" 24 | _zip = "postal" 25 | _agree_to_terms_checkbox = "agreed_to_terms_checkbox" 26 | _submit_enroll = "//button[@id='confirm-purchase']/parent::div" 27 | 28 | ############################ 29 | ### Element Interactions ### 30 | ############################ 31 | 32 | def enterCourseName(self, name): 33 | self.sendKeys(name, locator=self._search_box) 34 | self.elementClick(locator=self._search_course_icon) 35 | 36 | def selectCourseToEnroll(self, fullCourseName): 37 | self.elementClick(locator=self._course.format(fullCourseName), locatorType="xpath") 38 | 39 | def clickOnEnrollButton(self): 40 | self.elementClick(locator=self._enroll_button) 41 | 42 | def enterCardNum(self, num): 43 | self.switchToFrame(name="__privateStripeFrame4") 44 | self.sendKeys(num, locator=self._cc_num, locatorType="xpath") 45 | self.switchToDefaultContent() 46 | 47 | def enterCardExp(self, exp): 48 | self.switchToFrame(name="__privateStripeFrame5") 49 | self.sendKeys(exp, locator=self._cc_exp, locatorType="name") 50 | self.switchToDefaultContent() 51 | 52 | def enterCardCVV(self, cvv): 53 | self.switchToFrame(name="__privateStripeFrame6") 54 | self.sendKeys(cvv, locator=self._cc_cvv, locatorType="name") 55 | self.switchToDefaultContent() 56 | 57 | def enterZip(self, zip): 58 | self.switchToFrame(name="__privateStripeFrame7") 59 | self.sendKeys(zip, locator=self._zip, locatorType="name") 60 | self.switchToDefaultContent() 61 | 62 | def clickAgreeToTermsCheckbox(self): 63 | self.elementClick(locator=self._agree_to_terms_checkbox) 64 | 65 | def clickEnrollSubmitButton(self): 66 | self.elementClick(locator=self._submit_enroll, locatorType="xpath") 67 | 68 | def enterCreditCardInformation(self, num, exp, cvv, zip): 69 | self.enterCardNum(num) 70 | self.enterCardExp(exp) 71 | self.enterCardCVV(cvv) 72 | self.enterZip(zip) 73 | 74 | def enrollCourse(self, num="", exp="", cvv="", zip=""): 75 | self.clickOnEnrollButton() 76 | self.webScroll(direction="down") 77 | self.enterCreditCardInformation(num, exp, cvv, zip) 78 | self.clickAgreeToTermsCheckbox() 79 | 80 | def verifyEnrollFailed(self): 81 | result = self.isEnabled(locator=self._submit_enroll, locatorType="xpath", 82 | info="Enroll Button") 83 | return not result -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/7_register_courses_tests.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from utilities.teststatus import TestStatus 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class RegisterCoursesTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def objectSetup(self, oneTimeSetUp): 11 | self.courses = RegisterCoursesPage(self.driver) 12 | self.ts = TestStatus(self.driver) 13 | 14 | @pytest.mark.run(order=1) 15 | def test_invalidEnrollment(self): 16 | self.courses.enterCourseName("JavaScript") 17 | self.courses.selectCourseToEnroll("JavaScript for beginners") 18 | self.courses.enrollCourse(num="1234 5678 9012 3456", exp="1220", cvv="444", zip="12345") 19 | result = self.courses.verifyEnrollFailed() 20 | self.ts.markFinal("test_invalidEnrollment", result, 21 | "Enrollment Failed Verification") -------------------------------------------------------------------------------- /CODES/S31 - Automation Framework -_ Practice Exercise/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S31 - Automation Framework -_ Practice Exercise/Thumbs.db -------------------------------------------------------------------------------- /CODES/S32 - Data Driven Testing/2_register_courses_multiple_data_set.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from utilities.teststatus import TestStatus 3 | import unittest, pytest 4 | from ddt import ddt, data, unpack 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | @ddt 8 | class RegisterMultipleCoursesTests(unittest.TestCase): 9 | 10 | @pytest.fixture(autouse=True) 11 | def objectSetup(self, oneTimeSetUp): 12 | self.courses = RegisterCoursesPage(self.driver) 13 | self.ts = TestStatus(self.driver) 14 | 15 | @pytest.mark.run(order=1) 16 | @data(("JavaScript for beginners", "10", "1220", "10"), ("Learn Python 3 from scratch", "20", "1220", "20")) 17 | @unpack 18 | def test_invalidEnrollment(self, courseName, ccNum, ccExp, ccCVV): 19 | self.courses.enterCourseName(courseName) 20 | self.courses.selectCourseToEnroll(courseName) 21 | self.courses.enrollCourse(num=ccNum, exp=ccExp, cvv=ccCVV) 22 | result = self.courses.verifyEnrollFailed() 23 | self.ts.markFinal("test_invalidEnrollment", result, 24 | "Enrollment Failed Verification") 25 | self.driver.find_element_by_link_text("All Courses").click() -------------------------------------------------------------------------------- /CODES/S32 - Data Driven Testing/3_read_data.py: -------------------------------------------------------------------------------- 1 | import csv 2 | def getCSVData(fileName): 3 | # create an empty list to store rows 4 | rows = [] 5 | # open the CSV file 6 | dataFile = open(fileName, "r") 7 | # create a CSV Reader from CSV file 8 | reader = csv.reader(dataFile) 9 | # skip the headers 10 | next(reader) 11 | # add rows from reader to list 12 | for row in reader: 13 | rows.append(row) 14 | return rows -------------------------------------------------------------------------------- /CODES/S32 - Data Driven Testing/4-testdata.csv: -------------------------------------------------------------------------------- 1 | courseName,ccNum,ccExp,ccCVV 2 | JavaScript for beginners,10,1220,10 3 | Learn Python 3 from scratch,20,1220,20 -------------------------------------------------------------------------------- /CODES/S32 - Data Driven Testing/4_read_data.py: -------------------------------------------------------------------------------- 1 | import csv 2 | def getCSVData(fileName): 3 | # create an empty list to store rows 4 | rows = [] 5 | # open the CSV file 6 | dataFile = open(fileName, "r") 7 | # create a CSV Reader from CSV file 8 | reader = csv.reader(dataFile) 9 | # skip the headers 10 | next(reader) 11 | # add rows from reader to list 12 | for row in reader: 13 | rows.append(row) 14 | return rows -------------------------------------------------------------------------------- /CODES/S32 - Data Driven Testing/4_register_courses_csv_data.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from utilities.teststatus import TestStatus 3 | import unittest, pytest 4 | from ddt import ddt, data, unpack 5 | from utilities.read_data import getCSVData 6 | import time 7 | 8 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 9 | @ddt 10 | class RegisterCoursesCSVDataTests(unittest.TestCase): 11 | 12 | @pytest.fixture(autouse=True) 13 | def objectSetup(self, oneTimeSetUp): 14 | self.courses = RegisterCoursesPage(self.driver) 15 | self.ts = TestStatus(self.driver) 16 | self.nav = NavigationPage(self.driver) 17 | 18 | def setUp(self): 19 | self.driver.find_element_by_link_text("All Courses").click() 20 | 21 | @pytest.mark.run(order=1) 22 | @data(*getCSVData("/Users/atomar/Documents/workspace_python/letskodeit/testdata.csv")) 23 | @unpack 24 | def test_invalidEnrollment(self, courseName, ccNum, ccExp, ccCVV): 25 | self.courses.enterCourseName(courseName) 26 | time.sleep(1) 27 | self.courses.selectCourseToEnroll(courseName) 28 | time.sleep(1) 29 | self.courses.enrollCourse(num=ccNum, exp=ccExp, cvv=ccCVV) 30 | time.sleep(1) 31 | result = self.courses.verifyEnrollFailed() 32 | self.ts.markFinal("test_invalidEnrollment", result, 33 | "Enrollment Failed Verification") -------------------------------------------------------------------------------- /CODES/S32 - Data Driven Testing/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S32 - Data Driven Testing/Thumbs.db -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/1_navigation_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class NavigationPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _my_courses = "All Courses" 15 | _all_courses = "My Courses" 16 | _practice = "Practice" 17 | _user_settings_icon = "//div[@id='navbar']//span[text()='User Settings']" 18 | 19 | def navigateToAllCourses(self): 20 | self.elementClick(locator=self._all_courses, locatorType="link") 21 | 22 | def navigateToMyCourses(self): 23 | self.elementClick(locator=self._my_courses, locatorType="link") 24 | 25 | def navigateToPractice(self): 26 | self.elementClick(locator=self._practice, locatorType="link") 27 | 28 | def navigateToUserSettings(self): 29 | self.elementClick(locator=self._user_settings_icon, locatorType="xpath") -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/1_register_courses_csv_data.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from pages.home.navigation_page import NavigationPage 3 | from utilities.teststatus import TestStatus 4 | import unittest, pytest 5 | from ddt import ddt, data, unpack 6 | from utilities.read_data import getCSVData 7 | import time 8 | 9 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 10 | @ddt 11 | class RegisterCoursesCSVDataTests(unittest.TestCase): 12 | 13 | @pytest.fixture(autouse=True) 14 | def objectSetup(self, oneTimeSetUp): 15 | self.courses = RegisterCoursesPage(self.driver) 16 | self.ts = TestStatus(self.driver) 17 | self.nav = NavigationPage(self.driver) 18 | 19 | def setUp(self): 20 | self.nav.navigateToAllCourses() 21 | 22 | @pytest.mark.run(order=1) 23 | @data(*getCSVData("/Users/atomar/Documents/workspace_python/letskodeit/testdata.csv")) 24 | @unpack 25 | def test_invalidEnrollment(self, courseName, ccNum, ccExp, ccCVV): 26 | self.courses.enterCourseName(courseName) 27 | time.sleep(1) 28 | self.courses.selectCourseToEnroll(courseName) 29 | time.sleep(1) 30 | self.courses.enrollCourse(num=ccNum, exp=ccExp, cvv=ccCVV) 31 | time.sleep(1) 32 | result = self.courses.verifyEnrollFailed() 33 | self.ts.markFinal("test_invalidEnrollment", result, 34 | "Enrollment Failed Verification") -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/2_login_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | from pages.home.navigation_page import NavigationPage 3 | import logging 4 | from base.basepage import BasePage 5 | 6 | class LoginPage(BasePage): 7 | 8 | log = cl.customLogger(logging.DEBUG) 9 | 10 | def __init__(self, driver): 11 | super().__init__(driver) 12 | self.driver = driver 13 | self.nav = NavigationPage(driver) 14 | 15 | # Locators 16 | _login_link = "Login" 17 | _email_field = "user_email" 18 | _password_field = "user_password" 19 | _login_button = "commit" 20 | 21 | def clickLoginLink(self): 22 | self.elementClick(self._login_link, locatorType="link") 23 | 24 | def enterEmail(self, email): 25 | self.sendKeys(email, self._email_field) 26 | 27 | def enterPassword(self, password): 28 | self.sendKeys(password, self._password_field) 29 | 30 | def clickLoginButton(self): 31 | self.elementClick(self._login_button, locatorType="name") 32 | 33 | def login(self, email="", password=""): 34 | self.clickLoginLink() 35 | self.enterEmail(email) 36 | self.enterPassword(password) 37 | self.clickLoginButton() 38 | 39 | def verifyLoginSuccessful(self): 40 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 41 | locatorType="xpath") 42 | return result 43 | 44 | def verifyLoginFailed(self): 45 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 46 | locatorType="xpath") 47 | return result 48 | 49 | def verifyLoginTitle(self): 50 | return self.verifyPageTitle("Let's Kode It") 51 | 52 | def logout(self): 53 | self.nav.navigateToUserSettings() 54 | self.elementClick(locator="//div[@id='navbar']//a[@href='/sign_out']", 55 | locatorType="xpath") -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/2_login_tests.py: -------------------------------------------------------------------------------- 1 | from pages.home.login_page import LoginPage 2 | from utilities.teststatus import TestStatus 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class LoginTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def objectSetup(self, oneTimeSetUp): 11 | self.lp = LoginPage(self.driver) 12 | self.ts = TestStatus(self.driver) 13 | 14 | @pytest.mark.run(order=2) 15 | def test_validLogin(self): 16 | self.lp.login("test@email.com", "abcabc") 17 | result1 = self.lp.verifyLoginTitle() 18 | self.ts.mark(result1, "Title Verification") 19 | result2 = self.lp.verifyLoginSuccessful() 20 | self.ts.markFinal("test_validLogin", result2, "Login Verification") 21 | 22 | @pytest.mark.run(order=1) 23 | def test_invalidLogin(self): 24 | self.lp.logout() 25 | self.lp.login("test@email.com", "abcabcabc") 26 | result = self.lp.verifyLoginFailed() 27 | assert result == True -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/3_test_suite_demo.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from tests.home.login_tests import LoginTests 3 | from tests.courses.register_courses_csv_data import RegisterCoursesCSVDataTests 4 | 5 | # Get all tests from the test classes 6 | tc1 = unittest.TestLoader().loadTestsFromTestCase(LoginTests) 7 | tc2 = unittest.TestLoader().loadTestsFromTestCase(RegisterCoursesCSVDataTests) 8 | 9 | # Create a test suite combining all test classes 10 | smokeTest = unittest.TestSuite([tc1, tc2]) 11 | 12 | unittest.TextTestRunner(verbosity=2).run(smokeTest) -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/4_login_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | from pages.home.navigation_page import NavigationPage 3 | import logging 4 | from base.basepage import BasePage 5 | 6 | class LoginPage(BasePage): 7 | 8 | log = cl.customLogger(logging.DEBUG) 9 | 10 | def __init__(self, driver): 11 | super().__init__(driver) 12 | self.driver = driver 13 | self.nav = NavigationPage(driver) 14 | 15 | # Locators 16 | _login_link = "Login" 17 | _email_field = "user_email" 18 | _password_field = "user_password" 19 | _login_button = "commit" 20 | 21 | def clickLoginLink(self): 22 | self.elementClick(self._login_link, locatorType="link") 23 | 24 | def enterEmail(self, email): 25 | self.sendKeys(email, self._email_field) 26 | 27 | def enterPassword(self, password): 28 | self.sendKeys(password, self._password_field) 29 | 30 | def clickLoginButton(self): 31 | self.elementClick(self._login_button, locatorType="name") 32 | 33 | def login(self, email="", password=""): 34 | self.clickLoginLink() 35 | self.enterEmail(email) 36 | self.enterPassword(password) 37 | self.clickLoginButton() 38 | 39 | def verifyLoginSuccessful(self): 40 | result = self.isElementPresent("//div[@id='navbar']//li[@class='dropdown']", 41 | locatorType="xpath") 42 | return result 43 | 44 | def verifyLoginFailed(self): 45 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 46 | locatorType="xpath") 47 | return result 48 | 49 | def verifyLoginTitle(self): 50 | return self.verifyPageTitle("Let's Kode It") 51 | 52 | def logout(self): 53 | self.nav.navigateToUserSettings() 54 | logoutLinkElement = self.waitForElement(locator="//div[@id='navbar']//a[@href='/sign_out']", 55 | locatorType="xpath", pollFrequency=1) 56 | self.elementClick(element=logoutLinkElement) -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/4_navigation_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class NavigationPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _my_courses = "All Courses" 15 | _all_courses = "My Courses" 16 | _practice = "Practice" 17 | _user_settings_icon = "//div[@id='navbar']//li[@class='dropdown']" 18 | 19 | 20 | def navigateToAllCourses(self): 21 | self.elementClick(locator=self._all_courses, locatorType="link") 22 | 23 | def navigateToMyCourses(self): 24 | self.elementClick(locator=self._my_courses, locatorType="link") 25 | 26 | def navigateToPractice(self): 27 | self.elementClick(locator=self._practice, locatorType="link") 28 | 29 | def navigateToUserSettings(self): 30 | userSettingsElement = self.waitForElement(locator=self._user_settings_icon, 31 | locatorType="xpath", pollFrequency=1) 32 | self.elementClick(element=userSettingsElement) -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/4_webdriverfactory.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package base 3 | 4 | WebDriver Factory class implementation 5 | It creates a webdriver instance based on browser configurations 6 | 7 | Example: 8 | wdf = WebDriverFactory(browser) 9 | wdf.getWebDriverInstance() 10 | """ 11 | import traceback 12 | from selenium import webdriver 13 | import os 14 | 15 | class WebDriverFactory(): 16 | 17 | def __init__(self, browser): 18 | """ 19 | Inits WebDriverFactory class 20 | 21 | Returns: 22 | None 23 | """ 24 | self.browser = browser 25 | """ 26 | Set chrome driver and iexplorer environment based on OS 27 | 28 | chromedriver = "C:/.../chromedriver.exe" 29 | os.environ["webdriver.chrome.driver"] = chromedriver 30 | self.driver = webdriver.Chrome(chromedriver) 31 | 32 | PREFERRED: Set the path on the machine where browser will be executed 33 | """ 34 | 35 | def getWebDriverInstance(self): 36 | """ 37 | Get WebDriver Instance based on the browser configuration 38 | 39 | Returns: 40 | 'WebDriver Instance' 41 | """ 42 | baseURL = "https://letskodeit.teachable.com/" 43 | if self.browser == "iexplorer": 44 | # Set ie driver 45 | driver = webdriver.Ie() 46 | elif self.browser == "firefox": 47 | driver = webdriver.Firefox() 48 | elif self.browser == "chrome": 49 | # Set chrome driver 50 | chromedriver = "/Users/atomar/Documents/workspace_personal/selenium/chromedriver" 51 | os.environ["webdriver.chrome.driver"] = chromedriver 52 | driver = webdriver.Chrome(chromedriver) 53 | driver.set_window_size(1440, 900) 54 | else: 55 | driver = webdriver.Firefox() 56 | # Setting Driver Implicit Time out for An Element 57 | driver.implicitly_wait(3) 58 | # Maximize the window 59 | driver.maximize_window() 60 | # Loading browser with App URL 61 | driver.get(baseURL) 62 | return driver -------------------------------------------------------------------------------- /CODES/S33 - Running Complete Test Suite/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S33 - Running Complete Test Suite/Thumbs.db -------------------------------------------------------------------------------- /CODES/S4 - Advanced Data Types/1-listdemo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Data type to store more than one value in one variable name 3 | List items are in brackets, separated with "," [ 1, 2, 3 ] 4 | """ 5 | 6 | cars = [ "bmw", "honda", "audi"] 7 | empty_list = [] 8 | print(empty_list) 9 | print(cars) 10 | 11 | print("*#"*20) 12 | 13 | print(cars[1]) 14 | 15 | num_list = [1, 2, 3] 16 | sum_num = num_list[0] + num_list[1] 17 | 18 | print(sum_num) 19 | 20 | more_cars = [ "bmw", "honda", "audi"] 21 | print(more_cars[1]) 22 | 23 | more_cars[1] = "Benz" 24 | 25 | print(more_cars[1]) 26 | print(more_cars) -------------------------------------------------------------------------------- /CODES/S4 - Advanced Data Types/2-listmethods.py: -------------------------------------------------------------------------------- 1 | """ 2 | Built-in methods to help manipulating a list 3 | """ 4 | 5 | cars = [ "bmw", "honda", "audi"] 6 | 7 | length = len(cars) 8 | print(length) 9 | 10 | cars.append("Benz") 11 | print(cars) 12 | 13 | cars.insert(1, "Jeep") 14 | print(cars) 15 | 16 | x = cars.index("honda") 17 | print(x) 18 | 19 | y = cars.pop() 20 | print(y) 21 | print(cars) 22 | 23 | cars.remove("Jeep") 24 | print(cars) 25 | 26 | slicing = cars[0:2] 27 | a = cars[1:] 28 | print(slicing) 29 | print(a) 30 | 31 | print("*#"*20) 32 | print(cars) 33 | cars.sort() 34 | 35 | print(cars) -------------------------------------------------------------------------------- /CODES/S4 - Advanced Data Types/3-dictdemo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Data type to store more than one value in one variable name, in terms of key value pairs 3 | Dictionary items are in brackets {} in key:value pairs, separated with "," {'k1':'v1', 'k2':'v2'} 4 | Not sequenced, no indexing -> Mapping 5 | """ 6 | 7 | car = {'make': 'bmw', 'model': '550i', 'year': 2016} 8 | print(car) 9 | 10 | d = {} 11 | 12 | model = car['model'] 13 | 14 | print(car['make']) 15 | print(model) 16 | 17 | d['one'] = 1 18 | d['two'] = 2 19 | 20 | print(d) 21 | 22 | sum_1 = d['two'] + 8 23 | print(sum_1) 24 | print(d) 25 | d['two'] = d['two'] + 8 26 | print(d) -------------------------------------------------------------------------------- /CODES/S4 - Advanced Data Types/4-dictnested.py: -------------------------------------------------------------------------------- 1 | """ 2 | Nested Dictionary: 3 | d = {'k1': {'nestk1':'nestvalue1', 'nestk2': 'nestvalue2'}} 4 | d['k1']['nestk1'] 5 | """ 6 | 7 | cars = {'bmw': {'model': '550i', 'year': 2016}, 'benz': {'model': 'E350', 'year': 2015}} 8 | bmw_year = cars['bmw']['year'] 9 | print(bmw_year) 10 | print(cars['benz']['model']) -------------------------------------------------------------------------------- /CODES/S4 - Advanced Data Types/5-dictmethods.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dictionary Methods 3 | """ 4 | 5 | car = {'make': 'bmw', 'model': '550i', 'year': 2016} 6 | cars = {'bmw': {'model': '550i', 'year': 2016}, 'benz': {'model': 'E350', 'year': 2015}} 7 | 8 | print(car.keys()) 9 | print(cars.keys()) 10 | print(car.values()) 11 | print(cars.values()) 12 | print(car.items()) 13 | 14 | car_copy = car.copy() 15 | print(car_copy) 16 | 17 | print(car.pop('model')) 18 | print(car) -------------------------------------------------------------------------------- /CODES/S4 - Advanced Data Types/6-tuplesdemo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tuple 3 | Like list but they are immutable 4 | It means you can't change them 5 | """ 6 | 7 | my_list = [1, 2, 3] 8 | print(my_list) 9 | 10 | my_list[0] = 0 11 | print(my_list) 12 | 13 | my_tuple = (1, 2, 3, 2, 2, 3) 14 | print(my_tuple) 15 | 16 | print(my_tuple[0]) 17 | 18 | print(my_tuple[1:]) 19 | 20 | print(my_tuple.index(2)) 21 | 22 | print(my_tuple.count(3)) -------------------------------------------------------------------------------- /CODES/S4 - Advanced Data Types/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S4 - Advanced Data Types/Thumbs.db -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/1-comparators.py: -------------------------------------------------------------------------------- 1 | """ 2 | == --> Value Equality 3 | != --> Not equal to 4 | < --> Less than 5 | > --> Greater than 6 | <= --> Less than or equal to 7 | >= --> Greater than or equal to 8 | """ 9 | 10 | bool_one = 10 == 11 11 | not_equal = 10 != 11 12 | less_than = 10 < 11 13 | greater_than = 10 > 9 14 | lt_eq = 10 <= 10 15 | gt_eq = 10 >= 11 - 1 16 | print (gt_eq) -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/1_navigation_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class NavigationPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _my_courses = "All Courses" 15 | _all_courses = "My Courses" 16 | _practice = "Practice" 17 | _user_settings_icon = "//div[@id='navbar']//span[text()='User Settings']" 18 | 19 | def navigateToAllCourses(self): 20 | self.elementClick(locator=self._all_courses, locatorType="link") 21 | 22 | def navigateToMyCourses(self): 23 | self.elementClick(locator=self._my_courses, locatorType="link") 24 | 25 | def navigateToPractice(self): 26 | self.elementClick(locator=self._practice, locatorType="link") 27 | 28 | def navigateToUserSettings(self): 29 | self.elementClick(locator=self._user_settings_icon, locatorType="xpath") -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/1_register_courses_csv_data.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from pages.home.navigation_page import NavigationPage 3 | from utilities.teststatus import TestStatus 4 | import unittest, pytest 5 | from ddt import ddt, data, unpack 6 | from utilities.read_data import getCSVData 7 | import time 8 | 9 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 10 | @ddt 11 | class RegisterCoursesCSVDataTests(unittest.TestCase): 12 | 13 | @pytest.fixture(autouse=True) 14 | def objectSetup(self, oneTimeSetUp): 15 | self.courses = RegisterCoursesPage(self.driver) 16 | self.ts = TestStatus(self.driver) 17 | self.nav = NavigationPage(self.driver) 18 | 19 | def setUp(self): 20 | self.nav.navigateToAllCourses() 21 | 22 | @pytest.mark.run(order=1) 23 | @data(*getCSVData("/Users/atomar/Documents/workspace_python/letskodeit/testdata.csv")) 24 | @unpack 25 | def test_invalidEnrollment(self, courseName, ccNum, ccExp, ccCVV): 26 | self.courses.enterCourseName(courseName) 27 | time.sleep(1) 28 | self.courses.selectCourseToEnroll(courseName) 29 | time.sleep(1) 30 | self.courses.enrollCourse(num=ccNum, exp=ccExp, cvv=ccCVV) 31 | time.sleep(1) 32 | result = self.courses.verifyEnrollFailed() 33 | self.ts.markFinal("test_invalidEnrollment", result, 34 | "Enrollment Failed Verification") -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/2-boolean-operators.py: -------------------------------------------------------------------------------- 1 | """ 2 | and 3 | ************************************** 4 | True and True --> True 5 | True and False --> False 6 | False and False --> False 7 | ************************************** 8 | 9 | or 10 | ************************************** 11 | True or True --> True 12 | True or False --> True 13 | False or False --> False 14 | ************************************** 15 | 16 | not 17 | ************************************** 18 | Not True --> False 19 | Not False --> True 20 | """ 21 | 22 | and_output1 = (10 == 10) and (10 > 9) 23 | and_output2 = (10 == 10) and (10 < 9) 24 | and_output3 = (10 > 10) and (10 < 9) 25 | 26 | or_output1 = (10 == 10) or (10 > 9) 27 | or_output2 = (10 == 10) or (10 < 9) 28 | or_output3 = (10 > 10) or (10 < 9) 29 | 30 | not_true = not (10 == 10) 31 | not_false = not (10 > 10) 32 | 33 | print(not_false) -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/2_login_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | from pages.home.navigation_page import NavigationPage 3 | import logging 4 | from base.basepage import BasePage 5 | 6 | class LoginPage(BasePage): 7 | 8 | log = cl.customLogger(logging.DEBUG) 9 | 10 | def __init__(self, driver): 11 | super().__init__(driver) 12 | self.driver = driver 13 | self.nav = NavigationPage(driver) 14 | 15 | # Locators 16 | _login_link = "Login" 17 | _email_field = "user_email" 18 | _password_field = "user_password" 19 | _login_button = "commit" 20 | 21 | def clickLoginLink(self): 22 | self.elementClick(self._login_link, locatorType="link") 23 | 24 | def enterEmail(self, email): 25 | self.sendKeys(email, self._email_field) 26 | 27 | def enterPassword(self, password): 28 | self.sendKeys(password, self._password_field) 29 | 30 | def clickLoginButton(self): 31 | self.elementClick(self._login_button, locatorType="name") 32 | 33 | def login(self, email="", password=""): 34 | self.clickLoginLink() 35 | self.enterEmail(email) 36 | self.enterPassword(password) 37 | self.clickLoginButton() 38 | 39 | def verifyLoginSuccessful(self): 40 | result = self.isElementPresent("//*[@id='navbar']//span[text()='User Settings']", 41 | locatorType="xpath") 42 | return result 43 | 44 | def verifyLoginFailed(self): 45 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 46 | locatorType="xpath") 47 | return result 48 | 49 | def verifyLoginTitle(self): 50 | return self.verifyPageTitle("Let's Kode It") 51 | 52 | def logout(self): 53 | self.nav.navigateToUserSettings() 54 | self.elementClick(locator="//div[@id='navbar']//a[@href='/sign_out']", 55 | locatorType="xpath") -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/2_login_tests.py: -------------------------------------------------------------------------------- 1 | from pages.home.login_page import LoginPage 2 | from utilities.teststatus import TestStatus 3 | import unittest 4 | import pytest 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | class LoginTests(unittest.TestCase): 8 | 9 | @pytest.fixture(autouse=True) 10 | def objectSetup(self, oneTimeSetUp): 11 | self.lp = LoginPage(self.driver) 12 | self.ts = TestStatus(self.driver) 13 | 14 | @pytest.mark.run(order=2) 15 | def test_validLogin(self): 16 | self.lp.login("test@email.com", "abcabc") 17 | result1 = self.lp.verifyLoginTitle() 18 | self.ts.mark(result1, "Title Verification") 19 | result2 = self.lp.verifyLoginSuccessful() 20 | self.ts.markFinal("test_validLogin", result2, "Login Verification") 21 | 22 | @pytest.mark.run(order=1) 23 | def test_invalidLogin(self): 24 | self.lp.logout() 25 | self.lp.login("test@email.com", "abcabcabc") 26 | result = self.lp.verifyLoginFailed() 27 | assert result == True -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/2_register_courses_multiple_data_set.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from utilities.teststatus import TestStatus 3 | import unittest, pytest 4 | from ddt import ddt, data, unpack 5 | 6 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 7 | @ddt 8 | class RegisterMultipleCoursesTests(unittest.TestCase): 9 | 10 | @pytest.fixture(autouse=True) 11 | def objectSetup(self, oneTimeSetUp): 12 | self.courses = RegisterCoursesPage(self.driver) 13 | self.ts = TestStatus(self.driver) 14 | 15 | @pytest.mark.run(order=1) 16 | @data(("JavaScript for beginners", "10", "1220", "10"), ("Learn Python 3 from scratch", "20", "1220", "20")) 17 | @unpack 18 | def test_invalidEnrollment(self, courseName, ccNum, ccExp, ccCVV): 19 | self.courses.enterCourseName(courseName) 20 | self.courses.selectCourseToEnroll(courseName) 21 | self.courses.enrollCourse(num=ccNum, exp=ccExp, cvv=ccCVV) 22 | result = self.courses.verifyEnrollFailed() 23 | self.ts.markFinal("test_invalidEnrollment", result, 24 | "Enrollment Failed Verification") 25 | self.driver.find_element_by_link_text("All Courses").click() -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/3-boolean-precedence.py: -------------------------------------------------------------------------------- 1 | """ 2 | 1. not 3 | 2. and 4 | 3. or 5 | """ 6 | 7 | bool_output = True or not False and False 8 | # True 9 | print(bool_output) 10 | 11 | bool_output_1 = (10 == 10 or not 10 > 10) and 10 > 10 12 | # True or True -> True and False -> False 13 | print(bool_output_1) -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/3_read_data.py: -------------------------------------------------------------------------------- 1 | import csv 2 | def getCSVData(fileName): 3 | # create an empty list to store rows 4 | rows = [] 5 | # open the CSV file 6 | dataFile = open(fileName, "r") 7 | # create a CSV Reader from CSV file 8 | reader = csv.reader(dataFile) 9 | # skip the headers 10 | next(reader) 11 | # add rows from reader to list 12 | for row in reader: 13 | rows.append(row) 14 | return rows -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/3_test_suite_demo.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from tests.home.login_tests import LoginTests 3 | from tests.courses.register_courses_csv_data import RegisterCoursesCSVDataTests 4 | 5 | # Get all tests from the test classes 6 | tc1 = unittest.TestLoader().loadTestsFromTestCase(LoginTests) 7 | tc2 = unittest.TestLoader().loadTestsFromTestCase(RegisterCoursesCSVDataTests) 8 | 9 | # Create a test suite combining all test classes 10 | smokeTest = unittest.TestSuite([tc1, tc2]) 11 | 12 | unittest.TextTestRunner(verbosity=2).run(smokeTest) -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/4-testdata.csv: -------------------------------------------------------------------------------- 1 | courseName,ccNum,ccExp,ccCVV 2 | JavaScript for beginners,10,1220,10 3 | Learn Python 3 from scratch,20,1220,20 -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/4_login_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | from pages.home.navigation_page import NavigationPage 3 | import logging 4 | from base.basepage import BasePage 5 | 6 | class LoginPage(BasePage): 7 | 8 | log = cl.customLogger(logging.DEBUG) 9 | 10 | def __init__(self, driver): 11 | super().__init__(driver) 12 | self.driver = driver 13 | self.nav = NavigationPage(driver) 14 | 15 | # Locators 16 | _login_link = "Login" 17 | _email_field = "user_email" 18 | _password_field = "user_password" 19 | _login_button = "commit" 20 | 21 | def clickLoginLink(self): 22 | self.elementClick(self._login_link, locatorType="link") 23 | 24 | def enterEmail(self, email): 25 | self.sendKeys(email, self._email_field) 26 | 27 | def enterPassword(self, password): 28 | self.sendKeys(password, self._password_field) 29 | 30 | def clickLoginButton(self): 31 | self.elementClick(self._login_button, locatorType="name") 32 | 33 | def login(self, email="", password=""): 34 | self.clickLoginLink() 35 | self.enterEmail(email) 36 | self.enterPassword(password) 37 | self.clickLoginButton() 38 | 39 | def verifyLoginSuccessful(self): 40 | result = self.isElementPresent("//div[@id='navbar']//li[@class='dropdown']", 41 | locatorType="xpath") 42 | return result 43 | 44 | def verifyLoginFailed(self): 45 | result = self.isElementPresent("//div[contains(text(),'Invalid email or password')]", 46 | locatorType="xpath") 47 | return result 48 | 49 | def verifyLoginTitle(self): 50 | return self.verifyPageTitle("Let's Kode It") 51 | 52 | def logout(self): 53 | self.nav.navigateToUserSettings() 54 | logoutLinkElement = self.waitForElement(locator="//div[@id='navbar']//a[@href='/sign_out']", 55 | locatorType="xpath", pollFrequency=1) 56 | self.elementClick(element=logoutLinkElement) -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/4_navigation_page.py: -------------------------------------------------------------------------------- 1 | import utilities.custom_logger as cl 2 | import logging 3 | from base.basepage import BasePage 4 | 5 | class NavigationPage(BasePage): 6 | 7 | log = cl.customLogger(logging.DEBUG) 8 | 9 | def __init__(self, driver): 10 | super().__init__(driver) 11 | self.driver = driver 12 | 13 | # Locators 14 | _my_courses = "All Courses" 15 | _all_courses = "My Courses" 16 | _practice = "Practice" 17 | _user_settings_icon = "//div[@id='navbar']//li[@class='dropdown']" 18 | 19 | 20 | def navigateToAllCourses(self): 21 | self.elementClick(locator=self._all_courses, locatorType="link") 22 | 23 | def navigateToMyCourses(self): 24 | self.elementClick(locator=self._my_courses, locatorType="link") 25 | 26 | def navigateToPractice(self): 27 | self.elementClick(locator=self._practice, locatorType="link") 28 | 29 | def navigateToUserSettings(self): 30 | userSettingsElement = self.waitForElement(locator=self._user_settings_icon, 31 | locatorType="xpath", pollFrequency=1) 32 | self.elementClick(element=userSettingsElement) -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/4_read_data.py: -------------------------------------------------------------------------------- 1 | import csv 2 | def getCSVData(fileName): 3 | # create an empty list to store rows 4 | rows = [] 5 | # open the CSV file 6 | dataFile = open(fileName, "r") 7 | # create a CSV Reader from CSV file 8 | reader = csv.reader(dataFile) 9 | # skip the headers 10 | next(reader) 11 | # add rows from reader to list 12 | for row in reader: 13 | rows.append(row) 14 | return rows -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/4_register_courses_csv_data.py: -------------------------------------------------------------------------------- 1 | from pages.courses.register_courses_page import RegisterCoursesPage 2 | from utilities.teststatus import TestStatus 3 | import unittest, pytest 4 | from ddt import ddt, data, unpack 5 | from utilities.read_data import getCSVData 6 | import time 7 | 8 | @pytest.mark.usefixtures("oneTimeSetUp", "setUp") 9 | @ddt 10 | class RegisterCoursesCSVDataTests(unittest.TestCase): 11 | 12 | @pytest.fixture(autouse=True) 13 | def objectSetup(self, oneTimeSetUp): 14 | self.courses = RegisterCoursesPage(self.driver) 15 | self.ts = TestStatus(self.driver) 16 | self.nav = NavigationPage(self.driver) 17 | 18 | def setUp(self): 19 | self.driver.find_element_by_link_text("All Courses").click() 20 | 21 | @pytest.mark.run(order=1) 22 | @data(*getCSVData("/Users/atomar/Documents/workspace_python/letskodeit/testdata.csv")) 23 | @unpack 24 | def test_invalidEnrollment(self, courseName, ccNum, ccExp, ccCVV): 25 | self.courses.enterCourseName(courseName) 26 | time.sleep(1) 27 | self.courses.selectCourseToEnroll(courseName) 28 | time.sleep(1) 29 | self.courses.enrollCourse(num=ccNum, exp=ccExp, cvv=ccCVV) 30 | time.sleep(1) 31 | result = self.courses.verifyEnrollFailed() 32 | self.ts.markFinal("test_invalidEnrollment", result, 33 | "Enrollment Failed Verification") -------------------------------------------------------------------------------- /CODES/S5 - Comparison And Boolean Operators/4_webdriverfactory.py: -------------------------------------------------------------------------------- 1 | """ 2 | @package base 3 | 4 | WebDriver Factory class implementation 5 | It creates a webdriver instance based on browser configurations 6 | 7 | Example: 8 | wdf = WebDriverFactory(browser) 9 | wdf.getWebDriverInstance() 10 | """ 11 | import traceback 12 | from selenium import webdriver 13 | import os 14 | 15 | class WebDriverFactory(): 16 | 17 | def __init__(self, browser): 18 | """ 19 | Inits WebDriverFactory class 20 | 21 | Returns: 22 | None 23 | """ 24 | self.browser = browser 25 | """ 26 | Set chrome driver and iexplorer environment based on OS 27 | 28 | chromedriver = "C:/.../chromedriver.exe" 29 | os.environ["webdriver.chrome.driver"] = chromedriver 30 | self.driver = webdriver.Chrome(chromedriver) 31 | 32 | PREFERRED: Set the path on the machine where browser will be executed 33 | """ 34 | 35 | def getWebDriverInstance(self): 36 | """ 37 | Get WebDriver Instance based on the browser configuration 38 | 39 | Returns: 40 | 'WebDriver Instance' 41 | """ 42 | baseURL = "https://letskodeit.teachable.com/" 43 | if self.browser == "iexplorer": 44 | # Set ie driver 45 | driver = webdriver.Ie() 46 | elif self.browser == "firefox": 47 | driver = webdriver.Firefox() 48 | elif self.browser == "chrome": 49 | # Set chrome driver 50 | chromedriver = "/Users/atomar/Documents/workspace_personal/selenium/chromedriver" 51 | os.environ["webdriver.chrome.driver"] = chromedriver 52 | driver = webdriver.Chrome(chromedriver) 53 | driver.set_window_size(1440, 900) 54 | else: 55 | driver = webdriver.Firefox() 56 | # Setting Driver Implicit Time out for An Element 57 | driver.implicitly_wait(3) 58 | # Maximize the window 59 | driver.maximize_window() 60 | # Loading browser with App URL 61 | driver.get(baseURL) 62 | return driver -------------------------------------------------------------------------------- /CODES/S6 - Program Control Flow/1-conditional.py: -------------------------------------------------------------------------------- 1 | """ 2 | Conditional Logic 3 | """ 4 | 5 | if 100 > 10: 6 | print("Hundred is greater than 10") 7 | 8 | value = 'red' 9 | 10 | if value == 'green': 11 | print("Go") 12 | elif value == 'yellow': 13 | print("Prepare to stop") 14 | else: 15 | print("Stop") 16 | 17 | print("It will always print") 18 | -------------------------------------------------------------------------------- /CODES/S6 - Program Control Flow/2-whiledemo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Execute statements repeatedly 3 | Conditions are used to stop the execution of loops 4 | Iterable items are Strings, List, Tuple, Dictionary 5 | """ 6 | 7 | x = 0 8 | while x < 10: 9 | print("Value of x is: " + str(x)) 10 | x = x + 1 11 | 12 | l = [] 13 | num = 0 14 | while num < 10: 15 | l.append(num) 16 | print("Value of num is: " + str(num)) 17 | num += 1 18 | 19 | print(l) -------------------------------------------------------------------------------- /CODES/S6 - Program Control Flow/3-breakcontinue.py: -------------------------------------------------------------------------------- 1 | """ 2 | Break: To break out of the closest enclosing loop 3 | Continue: Go to the start of the closest enclosing loop 4 | """ 5 | 6 | x = 0 7 | while x < 10: 8 | print("Value of x is: " + str(x)) 9 | x = x + 1 10 | 11 | if x == 8: 12 | break 13 | print("This example is awesome") 14 | print("*"*20) 15 | else: 16 | print("Just broke out of the loop") 17 | 18 | # x = 0 19 | # while x < 10: 20 | # print("Value of x is: " + str(x)) 21 | # x = x + 1 22 | # 23 | # if x == 8: 24 | # continue 25 | # print("This example is awesome") 26 | # print("*"*20) 27 | # 28 | # print("Just broke out of the loop") -------------------------------------------------------------------------------- /CODES/S6 - Program Control Flow/4-forloopdemo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Execute statements repeatedly 3 | Conditions are used to stop the execution of loops 4 | Iterable items are Strings, List, Tuple, Dictionary 5 | """ 6 | # Strings for loop 7 | my_string = 'abcabc' 8 | 9 | for c in my_string: 10 | if c == 'a': 11 | print('A', end=' ') 12 | else: 13 | print(c, end=' ') 14 | 15 | print() 16 | 17 | # List for loop 18 | cars = ['bmw', 'benz', 'honda'] 19 | 20 | for car in cars: 21 | print(car) 22 | 23 | nums = [1, 2, 3] 24 | for n in nums: 25 | print(n * 10) 26 | 27 | print("*"*20) 28 | 29 | # Dictionary for loop 30 | d = {'one': 1, 'two': 2, 'three': 3} 31 | for k in d: 32 | print(k + " " + str(d[k])) 33 | 34 | print("*"*20) 35 | 36 | for k,v in d.items(): 37 | print(k) 38 | print(v) -------------------------------------------------------------------------------- /CODES/S6 - Program Control Flow/5-multiplelist.py: -------------------------------------------------------------------------------- 1 | """ 2 | Iterating multiple lists at the same time 3 | """ 4 | 5 | l1 = [1, 2, 3] 6 | l2 = [6, 7, 8, 20, 30, 40] 7 | 8 | for a, b in zip(l1, l2): 9 | if a > b: 10 | print(a) 11 | else: 12 | print(b) -------------------------------------------------------------------------------- /CODES/S6 - Program Control Flow/6-rangedemo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Built-in function 3 | Creates a sequence of numbers but does not save them in memory 4 | Very useful for generating numbers 5 | """ 6 | 7 | a = range(0, 20, 6) 8 | print(a) 9 | print(type(a)) 10 | 11 | print(list(a)) 12 | 13 | 14 | l = [1, 2, 3] 15 | 16 | for num in range(1, 4): 17 | print(num) -------------------------------------------------------------------------------- /CODES/S7 - Functions-Methods - Working With Reusable Code/1-methodsdemo1.py: -------------------------------------------------------------------------------- 1 | """ 2 | A group of code statements which can perform some specific task 3 | Methods are reusable and can be called when needed in the code 4 | """ 5 | def sum_nums(n1, n2): 6 | print(n1 + n2) 7 | 8 | sum_nums(2, 8) 9 | 10 | sum_nums(3, 3) 11 | 12 | l = [1, 2, 3] 13 | print(l.append(4)) 14 | print(l) 15 | 16 | print(len(l)) -------------------------------------------------------------------------------- /CODES/S7 - Functions-Methods - Working With Reusable Code/2-methodsdemo2.py: -------------------------------------------------------------------------------- 1 | """ 2 | A group of code statements which can perform some specific task 3 | Methods are reusable and can be called when needed in the code 4 | """ 5 | 6 | def sum_nums(n1, n2): 7 | """ 8 | Get sum of two numbers 9 | :param n1: 10 | :param n2: 11 | :return: 12 | """ 13 | return n1 + n2 14 | 15 | sum1 = sum_nums(2, 8) 16 | 17 | sum2 = sum_nums(3, 3) 18 | 19 | string_add = sum_nums('one', 2) 20 | print(string_add) 21 | 22 | print(sum1) 23 | print("*************") 24 | 25 | def isMetro(city): 26 | l = ['sfo', 'nyc', 'la'] 27 | 28 | if city in l: 29 | return True 30 | else: 31 | return False 32 | 33 | x = isMetro('boston') 34 | print(x) -------------------------------------------------------------------------------- /CODES/S7 - Functions-Methods - Working With Reusable Code/3-methodsdemo3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Positional Parameters 3 | They are like optional parameters 4 | And can be assigned a default value, if no value is provided from outside 5 | """ 6 | 7 | def sum_nums(n1, n2=4): 8 | """ 9 | Get sum of two numbers 10 | :param n1: 11 | :param n2: 12 | :return: 13 | """ 14 | return n1 + n2 15 | 16 | sum1 = sum_nums(4, n2=12) 17 | print(sum1) -------------------------------------------------------------------------------- /CODES/S7 - Functions-Methods - Working With Reusable Code/4-methodsdemo4.py: -------------------------------------------------------------------------------- 1 | """ 2 | Variable Scope 3 | """ 4 | 5 | a = 10 6 | 7 | def test_method(a): 8 | print("Value of local 'a' is: " + str(a)) 9 | a = 2 10 | print("New value of local 'a' is: " + str(a)) 11 | 12 | print("Value of global 'a' is: " + str(a)) 13 | test_method(a) 14 | print("Did the value of global 'a' change? " + str(a)) 15 | 16 | a = 10 17 | 18 | def test_method(): 19 | global a 20 | print("Value of 'a' inside the method is: " + str(a)) 21 | a = 2 22 | print("New value of 'a' inside the method is changed to: " + str(a)) 23 | 24 | print("Value of global a is: " + str(a)) 25 | test_method() 26 | print("Did the value of global 'a' change? " + str(a)) -------------------------------------------------------------------------------- /CODES/S7 - Functions-Methods - Working With Reusable Code/5-built-in-functions.py: -------------------------------------------------------------------------------- 1 | """ 2 | Some built-in functions 3 | max(): It takes any number of arguments and returns the largest one. 4 | 5 | min(): It takes any number of arguments and returns the smallest one. 6 | 7 | abs(): It returns the absolute value of the number, that number's distance from 0. 8 | It always returns a positive value and it only takes a single number. 9 | 10 | type(): It returns the type of the data it receives as an argument. 11 | """ 12 | 13 | def largest_num(*args): 14 | print(max(args)) 15 | return(max(args)) 16 | 17 | largest_num(-20, -10, 0, 10, 100) 18 | 19 | def smallest_num(*args): 20 | print(min(args)) 21 | 22 | smallest_num(-20, -10, 0, 10, 100) 23 | 24 | def abs_function(a): 25 | print(abs(a)) 26 | 27 | abs_function(-20) 28 | abs_function(20) 29 | 30 | print("**********") 31 | 32 | print(type(99)) 33 | print(type(99.9)) 34 | print(type("99.9")) 35 | l = [1, 2, 3] 36 | print(type(l)) -------------------------------------------------------------------------------- /CODES/S7 - Functions-Methods - Working With Reusable Code/6-Method-Exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S7 - Functions-Methods - Working With Reusable Code/6-Method-Exercise.pdf -------------------------------------------------------------------------------- /CODES/S7 - Functions-Methods - Working With Reusable Code/6-methodexercise.py: -------------------------------------------------------------------------------- 1 | """ 2 | Methods Exercise 3 | Create a method, which takes the state and gross income as the arguments and returns the net income after deducting tax based on the state. 4 | 5 | Assume Federal Tax: 10% 6 | Assume state tax on your wish. 7 | 8 | You don’t have to do for all the states, just take 3-4 to solve the purpose of the exercise. 9 | """ 10 | 11 | def calculateNetIncome(gross, state): 12 | """ 13 | Calculate the net income after federal and state tax 14 | :param gross: Gross Income 15 | :param state: State Name 16 | :return: Net Income 17 | """ 18 | state_tax = {'CA': 10, 'NY': 9, 'TX': 0, 'NJ': 6} 19 | 20 | # Calculate net income after federal tax 21 | net = gross - (gross * .10) 22 | 23 | # Calculate net income after state tax 24 | if state in state_tax: 25 | net = net - (gross * state_tax[state] / 100) 26 | print("Your net income after all the heavy taxes is: " + str(net)) 27 | return net 28 | else: 29 | print("State not in the list") 30 | return None 31 | 32 | 33 | calculateNetIncome(100000, 'CA') -------------------------------------------------------------------------------- /CODES/S8 - Classes - Object Oriented Programming/1-classdemo1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Object Oriented Programming 3 | """ 4 | 5 | s = "this is a string" 6 | a = "one more string" 7 | s.upper() 8 | s.lower() 9 | 10 | print(type('s')) 11 | print(type('a')) 12 | print(type([1, 2, 3])) -------------------------------------------------------------------------------- /CODES/S8 - Classes - Object Oriented Programming/2-classdemo2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Object Oriented Programming 3 | """ 4 | 5 | class Car(object): 6 | 7 | def __init__(self, make, model="550i"): 8 | self.make = make 9 | self.model = model 10 | 11 | c1 = Car('bmw') 12 | print(c1.make) 13 | print(c1.model) 14 | 15 | c2 = Car('benz') 16 | print(c2.make) 17 | print(c2.model) -------------------------------------------------------------------------------- /CODES/S8 - Classes - Object Oriented Programming/3-classdemo3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Object Oriented Programming 3 | """ 4 | 5 | class Car(object): 6 | 7 | wheels = 4 8 | 9 | def __init__(self, make, model): 10 | self.make = make 11 | self.model = model 12 | 13 | def info(self): 14 | print("Make of the car: " + self.make) 15 | print("Model of the car: " + self.model) 16 | 17 | 18 | 19 | c1 = Car('bmw', '550i') 20 | print(c1.make) 21 | #c1.info() 22 | 23 | c2 = Car('benz', 'E350') 24 | print(c2.make) 25 | #c2.info() 26 | 27 | print(Car.wheels) -------------------------------------------------------------------------------- /CODES/S8 - Classes - Object Oriented Programming/4-classdemo-inheritance1.py: -------------------------------------------------------------------------------- 1 | 2 | class Car(object): 3 | 4 | def __init__(self): 5 | print("You just created the car instance") 6 | 7 | def drive(self): 8 | print("Car started...") 9 | 10 | def stop(self): 11 | print("Car stopped") 12 | 13 | class BMW(Car): 14 | 15 | def __init__(self): 16 | Car.__init__(self) 17 | print("You just created the BMW instance") 18 | 19 | 20 | 21 | c = Car() 22 | c.drive() 23 | c.stop() 24 | 25 | b = BMW() 26 | b.drive() 27 | b.stop() 28 | -------------------------------------------------------------------------------- /CODES/S8 - Classes - Object Oriented Programming/5-classdemo-inheritance2.py: -------------------------------------------------------------------------------- 1 | 2 | class Car(object): 3 | 4 | def __init__(self): 5 | print("You just created the car instance") 6 | 7 | def drive(self): 8 | print("Car started...") 9 | 10 | def stop(self): 11 | print("Car stopped") 12 | 13 | class BMW(Car): 14 | 15 | def __init__(self): 16 | Car.__init__(self) 17 | print("You just created the BMW instance") 18 | 19 | def drive(self): 20 | super(BMW, self).drive() 21 | print("You are driving a BMW, Enjoy...") 22 | 23 | def headsup_display(self): 24 | print("This is a unique feature") 25 | 26 | c = Car() 27 | c.drive() 28 | c.stop() 29 | 30 | b = BMW() 31 | b.drive() 32 | b.stop() 33 | b.headsup_display() 34 | -------------------------------------------------------------------------------- /CODES/S8 - Classes - Object Oriented Programming/6-Class-Exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/-Selenium-WebDriver-With-Python-3.x---Novice-To-Ninja-v-/7be863a0a9c8da7e31a413742da92c2fcfd0b38a/CODES/S8 - Classes - Object Oriented Programming/6-Class-Exercise.pdf -------------------------------------------------------------------------------- /CODES/S8 - Classes - Object Oriented Programming/6-classexercise.py: -------------------------------------------------------------------------------- 1 | 2 | class Fruit(object): 3 | 4 | def __init__(self): 5 | print("I am a fruit") 6 | 7 | def nutrition(self): 8 | print("I am full of vitamins") 9 | 10 | def fruit_shape(self): 11 | print("Every fruit can have different shape") 12 | 13 | class Orange(Fruit): 14 | 15 | def __init__(self): 16 | Fruit.__init__(self) 17 | print("I am Orange") 18 | 19 | def nutrition(self): 20 | print("I am full of vitamin c") 21 | 22 | def color(self): 23 | print("I keep it simple, the color is also orange") 24 | 25 | f = Fruit() 26 | f.nutrition() 27 | f.fruit_shape() 28 | 29 | o = Orange() 30 | o.nutrition() 31 | o.fruit_shape() 32 | o.color() -------------------------------------------------------------------------------- /CODES/S9 - Exception Handling/1-exceptionhandling1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Exceptions are errors 3 | We should handle exceptions in our code 4 | to make sure the code is working the way we want and is handling all the unwanted issues 5 | Link to 3.5 built-in exceptions - https://docs.python.org/3/library/exceptions.html 6 | """ 7 | 8 | def exceptionHandling(): 9 | try: 10 | a = 10 11 | b = 20 12 | c = 0 13 | 14 | d = (a + b) / c 15 | print(d) 16 | # except ZeroDivisionError: 17 | # print("Zero Division") 18 | # except TypeError: 19 | # print("Can't add string to integer") 20 | except: 21 | print("In the except block") 22 | 23 | exceptionHandling() -------------------------------------------------------------------------------- /CODES/S9 - Exception Handling/2-exceptionhandling2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Exceptions are errors 3 | """ 4 | 5 | def exceptionHandling(): 6 | try: 7 | a = 10 8 | b = 20 9 | c = 0 10 | 11 | d = (a + b) / c 12 | print(d) 13 | except: 14 | print("In the except block") 15 | else: 16 | print("Because there was no exception, else is executed") 17 | finally: 18 | print("Finally, always executed") 19 | 20 | exceptionHandling() -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Selenium WebDriver With Python 3.x - Novice To Ninja [Video] 2 | This is the code repository for [Selenium WebDriver With Python 3.x - Novice To Ninja [Video]](https://www.packtpub.com/application-development/real-world-projects-python-3x-video?utm_source=github&utm_medium=repository&utm_campaign=9781789953374), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the video course from start to finish. 3 | ## About the Video Course 4 | This course includes a wide range of topics from Selenium WebDriver basics and advanced, Python programming concepts, Unittest and Pytest frameworks, automation framework design (Page Objects, Data Driven, Reading CSV Files), logging infrastructure, cross-browser testing, interview preparation. All the materials are provided including the code files. You achieve two targets with one single course - The complete Python programming language and Selenium WebDriver automation. We start from beginners' level and go through to advanced level. This is a single course for everything you need to know related to Web UI automation. 5 | 6 |