Compare commits

..

1 Commits

Author SHA1 Message Date
961db28e24 Add .circleci/config.yml 2020-10-20 23:21:58 +01:00
19 changed files with 99 additions and 251 deletions

21
.circleci/config.yml Normal file
View File

@ -0,0 +1,21 @@
version: 2.1
orbs:
python: circleci/python@0.2.1
jobs:
build-and-test:
executor: python/default
steps:
- checkout
- python/load-cache
- python/install-deps
- python/save-cache
- run:
command: ./manage.py test
name: Test
workflows:
main:
jobs:
- build-and-test

View File

@ -1,65 +0,0 @@
# DISABLED
name: ChromeTests
on: [ push ]
jobs:
build:
runs-on: ubuntu-gitea
strategy:
matrix:
python-version: [ "3.12" ]
env:
CHROMEDRIVER_VERSION: 113.0.5672.63
CHROME_VERSION: 113.0.5672.0
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
mkdir drivers
- name: Prep the host environment for Chrome
run: |
apt update -y
apt upgrade -y
apt install -y fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libu2f-udev libcups2 libdrm2\
libgbm1 libgtk-3-0 libgtk-4-1 libnspr4 libnss3 libu2f-udev libvulkan1 libxcomposite1 libxdamage1 libxfixes3\
libxkbcommon0 libxrandr2 xdg-utils xvfb libx11-6 libx11-dev libice6 xorg xorg-dev
- name: Install Chrome and Chromedriver for Linux
if: runner.os == 'Linux'
run: |
wget https://storage.googleapis.com/chrome-for-testing-public/${CHROME_VERSION}/linux64/chrome-linux64.zip
wget https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip
unzip chrome-linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver chrome-linux64
- name: Verify Installation
run: |
export PATH=$PATH:${{gitea.workspace}}/chrome-linux64
which chrome
which chromedriver
chrome --version
chromedriver --version
- name: Run the pytests
run: |
export PATH=$PATH:${{gitea.workspace}}/chrome-linux64
export PATH=$PATH:${{gitea.workspace}}/drivers
pytest -vv -c pytest.ini -m chrome
- name: Run the behave tests
run: behave --tags=mark.chrome

View File

@ -1,57 +0,0 @@
name: EdgeTests
on: [ push ]
jobs:
build:
runs-on: ubuntu-gitea
strategy:
matrix:
python-version: [ "3.12" ]
env:
EDGEDRIVER_VERSION: 126.0.2592.102
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
mkdir drivers
- name: Prep the Debian repositories
run: |
apt update -y
apt upgrade -y
- name: Install Edge and EdgeDriver for Linux
if: runner.os == 'Linux'
run: |
wget https://msedgedriver.azureedge.net/${EDGEDRIVER_VERSION}/edgedriver_linux64.zip
unzip edgedriver_linux64.zip
mv msedgedriver drivers
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-dev.list'
sudo rm microsoft.gpg
apt update
apt install -y microsoft-edge-stable
- name: EdgeDriver for Windows
if: runner.os == 'Windows'
run: |
wget https://msedgedriver.azureedge.net/${EDGEDRIVER_VERSION}/edgedriver_win64.zip
unzip edgedriver_win64.zip
mv msedgedriver.exe drivers
List-Item -Recurse drivers
- name: Run the pytests
run: pytest -c pytest.ini -m edge
- name: Run the behave tests
run: behave --tags=mark.edge

View File

@ -1,24 +0,0 @@
name: Pylint
on: [ push ]
jobs:
build:
runs-on: ubuntu-gitea
strategy:
matrix:
python-version: [ "3.12" ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
python -m pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')

3
.gitignore vendored
View File

@ -6,6 +6,3 @@
**/__pycache/ **/__pycache/
.idea/ .idea/
.vscode/ .vscode/
.venv/
drivers/
chrome-linux64/

View File

@ -1,2 +0,0 @@
[MASTER]
disable=C0114, C0115, C0116

23
Pipfile Normal file
View File

@ -0,0 +1,23 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
flask = "*"
pytest = "*"
behave = "*"
selenium = "*"
webdriver_manager = "*"
msedge-selenium-tools = "*"
[packages]
flask = "*"
pytest = "*"
behave = "*"
selenium = "*"
webdriver_manager = "*"
msedge-selenium-tools = "*"
[requires]
python_version = "3.6"

View File

@ -1,5 +1,2 @@
# behave-framework # behave-framework
basic python test framework basic python test framework

View File

@ -1,69 +1,52 @@
# pylint: disable=too-few-public-methods
import os
import platform
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from conftest import CWD from msedge.selenium_tools import Edge, EdgeOptions
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
class BrowserDriver: class BrowserDriver:
@staticmethod @staticmethod
def get(browser=None, headless=True): def get(browser=None, headless=True):
valid_browsers = ['chrome', 'firefox', 'safari', 'edge'] if browser == "chrome":
if browser in valid_browsers: return chrome(headless)
browser_method = globals()[browser] elif browser == "firefox":
return browser_method(headless) return firefox(headless)
elif browser == "edge":
raise ValueError(f"'{browser}' is not a supported browser") return edge(headless)
elif browser == "safari":
return safari()
else:
raise ValueError("'{}' is not a supported browser".format(browser))
def chrome(headless=True): def chrome(headless=True):
chrome_path = os.path.join(CWD, 'chrome-linux64', 'chrome') options = webdriver.ChromeOptions()
driver_path = os.path.join(CWD, 'chrome-linux64', 'chromedriver') options.headless = headless
options = ChromeOptions()
options.binary_location = chrome_path
if headless:
options.add_argument("--headless")
options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-certificate-errors')
chrome_service = ChromeService(executable_path=driver_path) return webdriver.Chrome(
return webdriver.Chrome(service=chrome_service, options=options) ChromeDriverManager().install(),
options=options)
def firefox(headless=True): def firefox(headless=True):
options = FirefoxOptions() options = webdriver.FirefoxOptions()
if headless:
options.add_argument("--headless")
options.accept_insecure_certs = True options.accept_insecure_certs = True
return webdriver.Firefox(options=options) options.headless = headless
gecko_driver = GeckoDriverManager().install()
return webdriver.Firefox(
executable_path=gecko_driver,
options=options)
def edge(headless=True): def edge(headless=True):
options = EdgeOptions() options = EdgeOptions()
driver_name = "msedgedriver"
if platform.system() == 'Windows':
driver_name += ".exe"
edgedriver_loc = os.path.join(CWD, 'drivers', driver_name)
if os.path.isfile(edgedriver_loc):
print(f'\nThe file {edgedriver_loc} exists.\n')
else:
print(f'\nThe file {edgedriver_loc} does not exist!\n')
options.use_chromium = True options.use_chromium = True
options.add_argument('disable-gpu') options.headless = headless
options.add_argument("no-sandbox") edge_driver = EdgeChromiumDriverManager().install()
options.add_argument("disable-dev-shm-usage") driver = Edge(edge_driver, options=options)
if headless: return driver
options.add_argument('headless')
edge_service = EdgeService(executable_path=edgedriver_loc)
edge_driver = webdriver.Edge(service=edge_service, options=options)
return edge_driver
def safari(): def safari():

View File

@ -1,18 +1,13 @@
import configparser import configparser
import os
import pytest import pytest
CWD = os.path.dirname(os.path.realpath(__file__))
config = configparser.ConfigParser() config = configparser.ConfigParser()
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)
def headless(): def headless():
config_file = os.path.join(CWD, "fixtures.ini") return _str_to_bool(_read_config_section("fixtures.ini", "dev")["headless"])
dev_config = _read_config_section(config_file, 'dev')
return _str_to_bool(dev_config["headless"])
def _read_config_section(source, section): def _read_config_section(source, section):

View File

@ -1,5 +1,4 @@
Feature: Browser Demo Feature: Browser Demo
Scenario: Load test.io web page with chrome Scenario: Load test.io web page with chrome
Given I have a chrome driver Given I have a chrome driver
When I navigate to test.io When I navigate to test.io
@ -10,13 +9,12 @@ Feature: Browser Demo
When I navigate to test.io When I navigate to test.io
Then The page is displayed Then The page is displayed
@mark.edge @skip
Scenario: Load test.io web page with edge Scenario: Load test.io web page with edge
Given I have an edge driver Given I have an edge driver
When I navigate to test.io When I navigate to test.io
Then The page is displayed Then The page is displayed
@skip
Scenario: Load test.io web page with safari Scenario: Load test.io web page with safari
Given I have a safari driver Given I have a safari driver
When I navigate to test.io When I navigate to test.io

View File

@ -1,9 +1,5 @@
# pylint: disable=unused-argument
def before_all(context): def before_all(context):
# -- SET LOG LEVEL: behave --logging-level=ERROR ... # -- SET LOG LEVEL: behave --logging-level=ERROR ...
# on behave command-line or in "behave.ini". # on behave command-line or in "behave.ini".
context.config.setup_logging() context.config.setup_logging()
def after_scenario(context, scenario):
context.driver.quit()

View File

@ -1,34 +1,34 @@
# pylint: disable=no-name-in-module
from behave import then, when, given from behave import then, when, given
from browserdriver import BrowserDriver from browserdriver import BrowserDriver
@given('I have a firefox driver') @given('I have a firefox driver')
def get_firefox_driver(context): def step_impl(context):
context.driver = BrowserDriver.get("firefox") context.driver = BrowserDriver.get("firefox")
@given('I have a chrome driver') @given('I have a chrome driver')
def get_chrome_driver(context): def step_impl(context):
context.driver = BrowserDriver.get("chrome") context.driver = BrowserDriver.get("chrome")
@given('I have an edge driver') @given(u'I have an edge driver')
def get_edge_driver(context): def step_impl(context):
context.driver = BrowserDriver.get("edge") context.driver = BrowserDriver.get("edge")
@given('I have a safari driver') @given(u'I have a safari driver')
def get_safari_driver(context): def step_impl(context):
context.driver = BrowserDriver.get("safari") context.driver = BrowserDriver.get("safari")
@when('I navigate to test.io') @when('I navigate to test.io')
def navigate_to_testio(context): def step_impl(context):
context.driver.get("https://test.io") context.driver.get("https://test.io")
print(context.driver.title)
@then('The page is displayed') @then('The page is displayed')
def page_is_displayed(context): def step_impl(context):
assert context.driver.title == "Home | Test IO" assert context.driver.title == "QA Testing as a Service | test IO"

View File

@ -1,2 +1,2 @@
[dev] [dev]
headless=true headless = True

View File

@ -1,7 +1,3 @@
[pytest] [pytest]
addopts = -s -v --durations=0
testpaths = pytests testpaths = pytests
markers =
chrome: chrome tests only.
firefox: firefox tests only.
edge: msedge tests only.

View File

View File

@ -1,35 +1,31 @@
from browserdriver import BrowserDriver
import pytest import pytest
from browserdriver import BrowserDriver
@pytest.mark.firefox
def test_firefox_browser(headless): def test_firefox_browser(headless):
bd = BrowserDriver().get("firefox", headless=headless) bd = BrowserDriver().get("firefox", headless=headless)
bd.get('https://test.io') bd.get('https://test.io')
assert bd.title == "Home | Test IO" assert "QA Testing as a Service | test IO" == bd.title
bd.quit() bd.quit()
@pytest.mark.chrome
def test_chrome_browser(headless): def test_chrome_browser(headless):
bd = BrowserDriver().get("chrome", headless=headless) bd = BrowserDriver().get("chrome", headless=headless)
bd.get('https://test.io') bd.get('https://test.io')
assert bd.title == "Home | Test IO" assert "QA Testing as a Service | test IO" == bd.title
bd.quit() bd.quit()
@pytest.mark.skip(reason="Safari is not available") def test_safari_browser(headless):
def test_safari_browser():
bd = BrowserDriver().get("safari", headless=False) bd = BrowserDriver().get("safari", headless=False)
bd.get('https://test.io') bd.get('https://test.io')
assert bd.title == "Home | Test IO" assert "QA Testing as a Service | test IO" == bd.title
bd.quit() bd.quit()
@pytest.mark.edge @pytest.mark.skip(reason="Edge has inconsistent implementations across platforms")
def test_edge_browser(headless): def test_edge_browser(headless):
bd = BrowserDriver().get("edge", headless=headless) bd = BrowserDriver().get("edge", headless=headless)
bd.get('https://test.io') bd.get('https://test.io')
assert bd.title == "Home | Test IO" assert "QA Testing as a Service | test IO" == bd.title
bd.quit() bd.quit()

View File

@ -1,6 +0,0 @@
flask~=3.0.3
pytest~=8.3.1
pylint~=3.2.6
behave~=1.2.6
selenium~=4.23.0
webdriver-manager~=4.0.1