Skip to content

Instantly share code, notes, and snippets.

@3kwa
Last active December 18, 2015 10:39
Show Gist options
  • Save 3kwa/5770612 to your computer and use it in GitHub Desktop.
Save 3kwa/5770612 to your computer and use it in GitHub Desktop.
Dependencies for dead simple acceptance testing using pytest and selenium
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."
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