Skip to content

Commit

Permalink
add api test and use pip to install requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
qualityshepherd committed Nov 7, 2018
1 parent d1d5a16 commit 25eec5b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ def driver(request):
else:
raise ValueError('invalid driver name: ' + driver)
driver.set_window_size(1200, 800)
driver.base_url = request.config.getoption('--url') or 'https://qualityshepherd.com/'
yield driver
driver.quit()
8 changes: 6 additions & 2 deletions pages/base_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
base page class that is inherited by all pages and includes
things available to all pages
'''
class BasePage(object) :
base_url = 'https://qualityshepherd.com/'
class BasePage() :
timeout = {
's': 1,
'm': 3,
Expand All @@ -19,11 +18,16 @@ class BasePage(object) :

def __init__(self, driver):
self.driver = driver
self.base_url = driver.base_url

def goto(self, url):
''' wrapper for get() '''
url = self.base_url + url
self.driver.get(url)
return url

def get_base_url(self):
return self.base_url

def element(self, locator):
''' wait and get a single element via css selector (eg. #id) '''
Expand Down
4 changes: 1 addition & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ Example Selenium/Webdriver e2e tests (some quite silly) that aim to illustrate s

## Install
1. install pip: `sudo easy_install pip`
1. install [Pytest](https:pytest.org): `pip install -U pytest`
1. install/update selenium: `pip install -U selenium` (3.14.1)
1. install required packages: `pip3 install -r requirements.txt`
1. download drivers and copy to your path (eg. `/usr/local/bin`)
- https://github.com/mozilla/geckodriver/releases (v0.23.0)
- https://sites.google.com/a/chromium.org/chromedriver/downloads (2.43)
1. instaly pytest-parallel `pip3 install pytest-parallel` (assuming you're running python3.6+)

## Run Tests
1. in Chrome (default): `pytest`
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest~=3.10.0
selenium~=3.14.1
pytest-parallel
requests~=2.20.0
19 changes: 19 additions & 0 deletions tests/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from requests import get
from qs_page import QsPage


@pytest.fixture(scope="module", autouse=True)
def setup(driver):
global qsPage
qsPage = QsPage(driver)

def test_qualityshepherd_site_returns_status_200(driver):
res = get(qsPage.get_base_url())

assert res.status_code == 200

def test_non_existant_page_returns_404(driver):
res = get(qsPage.get_base_url() + '/this_page_no_exits.php')

assert res.status_code == 404

0 comments on commit 25eec5b

Please sign in to comment.