Giter VIP home page Giter VIP logo

python_google's Introduction

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

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

NOTES

If you're facing ChromeDriver issues, use the DriverManager library so it automatically installs the latest driver.

Step 2: Test displaying Test Results

Visit tag v1.0.0 Setup your test script as a unit test file by the following:

  1. Structure test as a class with param as "unittest.TestCase"
  2. Create a setup and teardown method for your driver
    • annotate it with @classmethod
  3. Insert your webdriver script into the method
  4. 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
  5. 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

Visit tag v1.0.0

Page Object Model makes it easier to:

  1. Build automation scripts quickly. If someone defined the page object and methods already, you can use it.
  2. More developer friendly. It's easier to understand the test behavior at a higher level
  3. Easier maintainance so if several page objects change, you can edit it quickly

So here's what I did:

  1. Create a Locators file so centralize page object definitions
  2. Create a SearchPage to define Webdriver actions in a higher level so it's easier to understand
  3. Refactor my current test script to use SearchPage

Now it's easier to read

Step 4: Add more tests

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.

Notes

python_google's People

Contributors

thebookknight avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.