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
Visit tag v1.0.0 See the attached requirements.txt
Quickly check if you can navigate to Google by scripting some navigational code. See test_search.py
If you're facing ChromeDriver issues, use the DriverManager library so it automatically installs the latest driver.
Visit tag v1.0.0 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
Visit tag v1.0.0
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
I added more tests. To run all the tests in the file, right-click the class name and run them. Since I'm testing on Google.com, I added an Explicit Wait since searching queries could take time to appear.
- Create an explicit wait from Python's WebDriverWait
- more StackOverflow details
- explicit waits will wait until the element is present before proceeding to next step