slateci.io Selenium Web App Unit Test
Selenium is a framework for automating web applications tests. It runs on OS's such as Windows, Mac OS, Linux and Solaris. It's supported browsers include Chrome, FireFox, Edge, Internet Explorer, Safari and Opera. The Selenium client API supports Java, Python, C#, Ruby, JavaScript and Kotlin.
.
├── ...
└── main.py
└── WebPageBrowsing # tests to iterate through web pages
├── test_home_page # check links on Home page
├── test_about_page # check links on About page
├── test_tech_page # check links on Technology page
├── test_docs_page # check links on Docs page
├── test_blog_page # check links on Blog page
└── test_comm_page # check links on Community page
In the slateci.io repo, the GitHub Actions testing procedure is set up in selenium-tests.yml. The test is set up tp run on push
or pull request
to the master
branch of the slateci.io repository. Below is the list of the test setup and running procedure:
- Setup Python 3.8
- Install Selenium Python bindings
- Install Chrome web driver. After installation, the path to the web driver will be at
/home/runner/work/slateci.github.io/slateci.github.io/chromedriver
- Download Selenium test. The test program in this repository will be downloaded to the GitHub Actions VM in the slateci.io repo
- Run Selenium Tests
- Post Slack to
#website
if the test failed.
Run the test suite on the production website:
[your@localmachine ~]$ docker run -it -v $PWD:/opt/project joyzoursky/python-chromedriver:3.9-selenium python /opt/project/main.py
INFO URL under test: https://slateci.io/
...
...
- Use the
$PWD:/opt/project
volume to mount files from the host to the container. - The Python installation in the image may be used as a remote interpreter in IDEs such as VSCode and IntelliJ.
Run the test suite on a local containerized build of the website:
[your@localmachine ~]$ docker run -it -v $PWD:/opt/project --network="host" joyzoursky/python-chromedriver:3.9-selenium python /opt/project/main.py http://localhost:4000
INFO URL under test: http://localhost:4000
...
...
- Use the
$PWD:/opt/project
volume to mount files from the host to the container. - The Python installation in the image may be used as a remote interpreter in IDEs such as VSCode and IntelliJ.
- Refer to slateci/slateci.github.io for additional information on running the website locally.
- Operating Systems: Linux or macOS
- Browsers: Chrome or Firefox
- Python 3
- Selenium library for Python
$ pip install selenium
- Reference: Selenium documentation
- Referenced Documentation
- Download and unzip the web driver
- This instruction assumes the download path is at
/opt/WebDriver/bin
. The users can specify other download path as needed.
- Selenium requires a web driver of corresponding version to interface with the installed Chrome. Check the Chrome version before installation
- For example, if the Chrome version is
84.0.4147.105
, thenChromeDriver 84.0.4147.30
should be downloaded from WebDriver for Chrome
$ export PATH=$PATH:/opt/WebDriver/bin >> ~/.profile
- If the above command does not work in macOS, add line
export PATH=$PATH:/opt/WebDriver/bin
to file~/.bash_profile
- macOS notarization requirement can prevent the web driver from running
- Navigate to the folder containing the web driver.
- For
chromedriver
run the following command:$ xattr -r -d com.apple.quarantine chromedriver
git clone
this repo to local machine- In
main.py
->setUp(self)
, change thepath
variable to the absolute path of the Chrome web driver in the local machine - In
main.py
->setUp(self)
, setoptions.headless = True
to run test in the background, or setoptions.headless = False
to run test on a open browser session - In the terminal,
cd
into the test program folder, run:$ python main.py