My Python Selenium Demo on Google page
Note: I used PyCharm IDE as it's easy to import necessary libraries and has an isolated virtual environment.
It also has linting rules to ensure what you code follows PEP 8
Step 1: Ensure correct dependencies are installed
See the attached requirements.txt
Quickly check if you can navigate to Google by scripting some navigational code. See test_search.py
NOTES
If you're facing ChromeDriver issues, use the DriverManager library so it automatically installs the latest driver.
Step 2: Test displaying Test Results
Setup your test script as a unit test file by the following:
- Structure test as a class with param as "unittest.TestCase"
- Create a setup and teardown method for your driver
- annotate it with @classmethod
- Insert your webdriver script into the method
- Go to "Run" > "Edit Configurations", then add your test file as a "Python Test"
- make sure the target file is the class file you just created
- When you right-click your python test file, you can click "Run" and it will run as unit tests
- you can see results in your PyCharm IDE below
Step 3: Implement Page Object Model
Page Object Model makes it easier to:
- Build automation scripts quickly. If someone defined the page object and methods already, you can use it.
- More developer friendly. It's easier to understand the test behavior at a higher level
- Easier maintainance so if several page objects change, you can edit it quickly
So here's what I did:
- Create a Locators file so centralize page object definitions
- Create a SearchPage to define Webdriver actions in a higher level so it's easier to understand
- Refactor my current test script to use SearchPage
Now it's easier to read