Coder Social home page Coder Social logo

martin-mok / python-selenium-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chiedo/python-selenium-starter

0.0 1.0 0.0 9.12 MB

A starter project structure for creating selenium tests with python

Shell 19.10% Batchfile 18.46% Python 62.44%

python-selenium-starter's Introduction

Python-selenium-starter

Starter set up for writing selenium tests with Python. The Goal is to make it easier to write and run tests using Selenium for multiple browsers and devices. With this repo, you should be able to just start writing your tests and not be concerned with the basic set up of your test framework. This has options to also run on browserstack but could easily be modified to use another service with some elementary coding.

Installing Selenium

  • Install pip first if needed obviously (google is your friend here)
  • pip install -U selenium

Getting Started

  • You can add more tests by adding modules to the tests directory. Copy the structure in the examples and your tests should be executed automagically by the above.
  • You will likely want to update the data in the config.py file. But should not need to update anything in the run.py file unless you are applying a general fix to this repo that you plan to contribute..

General Examples

To run all tests on Firefox

python run.py

To override the base url you set in run.py

python run.py --base_url "http://google.com"

To only run one test

python run.py --test "example_a.py"

To see more options

python run.py --help

Browserstack options

  • Before anything, you need to get your Selenium automate username and automate value from the following URL.https://www.browserstack.com/accounts/automate
  • Once you have those values modify your ~/.bash_profile to end with the following. (use ~/.bashrc instead if on linux)
export SELENIUM_AUTOMATE_USERNAME="REPLACE_THIS"
export SELENIUM_AUTOMATE_VALUE="REPLACE_THIS"
  • Then run the following in your terminal (remember to modify to ~/.bashrc if on linux)
source ~/.bash_profile

Open a tab and run the following to start the local testing server. That will make sure you can still access the site via the correct IP address, etc.

./local_testing_binaries/osx/BrowserStackLocal $SELENIUM_AUTOMATE_VALUE localhost,3000,0 -forcelocal -vv

Then Run the following to execute the tests and hook into the browser stack local testing server

python run.py --browserstack --use_local

Browserstack Examples

To run with only in the desktop browsers:

python run.py --browserstack --mobile

To run with only the in the desktop browsers:

python run.py --browserstack --desktop

To override the base url you set in run.py

python run.py --browserstack --capabilities "{'os_version': '7', 'browser_version': '8.0', 'os': 'Windows', 'resolution': '1024x768', 'browser': 'IE'}"

Browserstack Notes

  • For more browserstack options, you can see more details here https://www.browserstack.com/automate/python.
  • You will notice that your username and value are hard coded in those examples though. Just replace those areas with the environment variables we set up to make your code more shareable.
  • Local testing is VERY slow... Do as you wish

python-selenium-starter's People

Watchers

James Cloos 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.