Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Add example test script for quick try
Browse files Browse the repository at this point in the history
  • Loading branch information
joyzoursky committed Jul 18, 2018
1 parent bbf6d14 commit aaf630f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ For the following alpine based images:
- `3.6-alpine3.7-selenium`
- `2.7-alpine3.7`
- `2.7-alpine3.7-selenium`
run the followings in your terminal:

Run the followings in your terminal:

```
$ cd [your working directory]
Expand All @@ -63,7 +64,8 @@ For the following ubuntu based images:
- `2.7-selenium`
- `2.7-xvfb`
- `2.7-xvfb-selenium`
run the followings in your terminal:

Run the followings in your terminal:

```
$ cd [your working directory]
Expand All @@ -75,7 +77,7 @@ This will create a container from the image. Then you could starting running the

## Examples to run selenium test in the container:

You can download a selenium test example from [here](https://github.com/joyzoursky/selenium-template) to quick start.
You can download a selenium test example from [here](https://github.com/joyzoursky/docker-python-chromedriver/blob/master/test_script.py) to quick start.

For the following images with selenium pre-installed:
- `3.7-alpine3.8-selenium`
Expand All @@ -84,7 +86,8 @@ For the following images with selenium pre-installed:
- `3.6-selenium`
- `2.7-alpine3.7-selenium`
- `2.7-selenium`
you may run:

You may run:

```
# python test_script.py
Expand All @@ -98,14 +101,15 @@ For the following images that do not have selenium pre-installed:
- `3.6`
- `2.7-alpine3.7`
- `2.7`
you may run:

You may run:

```
# pip install selenium==3.13.0
# python test_script.py
```

*Don't install selenium version 3.8.1 to avoid the runtime error `ConnectionResetError: [Errno 104] Connection reset by peer`.*
*If you see the runtime error `ConnectionResetError: [Errno 104] Connection reset by peer`, revert your selenium version to 3.8.0.*

For `3.6-xvfb` or `2.7-xvfb`, you may run:

Expand Down
45 changes: 45 additions & 0 deletions test_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
A simple selenium test example written by python
"""

import unittest
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException

class TestTemplate(unittest.TestCase):
"""Include test cases on a given url"""

def setUp(self):
"""Start web driver"""
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(chrome_options=chrome_options)
self.driver.implicitly_wait(10)

def tearDown(self):
"""Stop web driver"""
self.driver.quit()

def test_case_1(self):
"""Find and click top-right button"""
try:
self.driver.get('https://www.oursky.com/')
el = self.driver.find_element_by_class_name('btn-header')
el.click()
except NoSuchElementException as ex:
self.fail(ex.msg)

def test_case_2(self):
"""Find and click Learn more button"""
try:
self.driver.get('https://www.oursky.com/')
el = self.driver.find_element_by_xpath(".//*[@id='tag-line-wrap']/span/a")
el.click()
except NoSuchElementException as ex:
self.fail(ex.msg)

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestTemplate)
unittest.TextTestRunner(verbosity=2).run(suite)

0 comments on commit aaf630f

Please sign in to comment.