Last active
December 18, 2015 10:39
-
-
Save 3kwa/5770612 to your computer and use it in GitHub Desktop.
Dependencies for dead simple acceptance testing using pytest and selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py | |
echo -e "Installing pip..." | |
sudo python get-pip.py | |
rm get-pip.py | |
echo -e "Done." | |
echo -e "Installing Python packages..." | |
sudo pip install pytest | |
sudo pip install selenium | |
sudo pip install ipython | |
sudo pip install tornado | |
sudo pip install pyzmq | |
echo -e "Done." | |
if [ -z $(which brew) ] | |
then | |
echo -e "Installing Homebrew..." | |
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" | |
echo -e "Done." | |
fi | |
echo -e "Installing Homebrew packages..." | |
brew install phantomjs | |
brew install chromedriver | |
echo -e "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from selenium import webdriver | |
BROWSER = {'chrome': webdriver.Chrome, | |
'firefox': webdriver.Firefox, | |
'headless': lambda: webdriver.PhantomJS(service_args=["--ignore-ssl-errors=yes"]) | |
} | |
def pytest_addoption(parser): | |
parser.addoption('--url', action='store') | |
parser.addoption('--browser', action='store', default='headless') | |
parser.addoption('--username', action='store') | |
parser.addoption('--password', action='store') | |
@pytest.fixture(scope="session") | |
def url(request): | |
return request.config.getoption('url') | |
@pytest.fixture(scope="session") | |
def username(request): | |
return request.config.getoption('username') | |
@pytest.fixture(scope="session") | |
def password(request): | |
return request.config.getoption('password') | |
@pytest.fixture(scope="session") | |
def browser(request): | |
browser = request.config.getoption('browser') | |
driver = BROWSER[browser]() | |
request.addfinalizer(lambda: driver.quit()) | |
return driver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment