Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium hub #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.7

COPY . .
RUN pip install --no-cache-dir -r ./requirements.txt
RUN pip install --no-cache-dir pytest mock

ENV BEHAVE_WEBDRIVER=Remote
ENV HUB_URL=http://localhost:4444/wd/hub
ENV DEMO_URL=http://demo-site
ENV ENV_BASE_URL=http://demo-site

ENV CAPS="Chrome"

CMD behave tests/features
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.7'

services:
hub:
image: selenium/hub:3.141.59-copernicium
ports:
- "4444:4444"

chrome:
image: selenium/node-chrome:3.141.59-copernicium
environment:
HUB_HOST: hub
HUB_PORT: 4444
deploy:
replicas: 1
entrypoint: bash -c 'SE_OPTS="-host $$HOSTNAME" /opt/bin/entry_point.sh'
depends_on:
- hub
- demo-site

firefox:
image: selenium/node-firefox:3.141.59-copernicium
environment:
HUB_HOST: hub
HUB_PORT: 4444
deploy:
replicas: 1
entrypoint: bash -c 'SE_OPTS="-host $$HOSTNAME" /opt/bin/entry_point.sh'
depends_on:
- hub
- demo-site

demo-site:
image: nginx
volumes:
- ./tests/demo-app:/usr/share/nginx/html:ro
4 changes: 0 additions & 4 deletions tests/features/baseUrl.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ Feature: Base URL configuration
As a developer
I should be able to change the base URL for opening pages.

Scenario: Default base is http://localhost:8000/
When I open the site "/"
Then I expect that the url is "http://localhost:8000/"

Scenario: Change the base url to http://127.0.0.1:8000/
Given the base url is "http://127.0.0.1:8000/"
When I open the site "/page.html"
Expand Down
2 changes: 2 additions & 0 deletions tests/features/baseUrlWithParameterTransformation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Feature: Base URL configuration supports parameter transformation
I should be able to change the base URL for opening pages
And I should be able to replace hardcoded values with parameters.

# {BASE_URL} / {ALT_BASE_URL} are transformed by transformer provided in environment.py
# As long the URLs are valid, this test should still work even if the test url is not available at those urls.
Scenario: Default base is http://localhost:8000/
When I open the site "/"
Then I expect that the url is "{BASE_URL}/"
Expand Down
17 changes: 14 additions & 3 deletions tests/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from behave_webdriver.driver import Chrome, ChromeOptions
from functools import partial
from behave_webdriver.fixtures import transformation_fixture, fixture_browser
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from behave_webdriver.transformers import FormatTransformer
from behave.fixture import use_fixture
import behave_webdriver
Expand All @@ -17,7 +18,12 @@ def get_driver(**kwargs):
args = []
kwargs.setdefault('default_wait', 5)
Driver = behave_webdriver.utils._from_env(default_driver='Chrome')
if Driver == behave_webdriver.Chrome:

if Driver == behave_webdriver.Remote:
caps_name = os.environ.get('CAPS').upper()
caps = getattr(DesiredCapabilities, caps_name).copy()

elif Driver == behave_webdriver.Chrome:
opts = ChromeOptions()
opts.add_argument('--no-sandbox') # for travis build
kwargs['chrome_options'] = opts
Expand All @@ -28,14 +34,19 @@ def get_driver(**kwargs):
else:
ex_path = shutil.which(Driver._driver_name) or pwd_driver_path
kwargs['executable_path'] = ex_path
if Driver == behave_webdriver.Remote:
del kwargs['executable_path']
kwargs['command_executor'] = os.environ.get('HUB_URL') or "http://hub:4444/wd/hub"
kwargs['desired_capabilities'] = caps
if os.environ.get('BEHAVE_WEBDRIVER_HEADLESS', None) and hasattr(Driver, 'headless'):
Driver = Driver.headless
return Driver, kwargs

#context.behave_driver = context.BehaveDriver()

def before_all(context):
driver, kwargs = get_driver()
if driver == behave_webdriver.Remote:
context.base_url = os.environ.get('DEMO_URL') or 'http://demo-site'
context.BehaveDriver = partial(driver, **kwargs)
use_fixture(fixture_browser, context, webdriver=driver, **kwargs)
use_fixture(transformation_fixture, context, FormatTransformer, BASE_URL='http://localhost:8000', ALT_BASE_URL='http://127.0.0.1:8000')
Expand All @@ -46,7 +57,7 @@ def before_tag(context, tag):


def before_feature(context, feature):
if "fresh_driver" in feature.tags:
if "fresh_driver" in feature.tags and context.behave_driver.__class__ != behave_webdriver.Remote:
context.behave_driver.quit()
context.behave_driver = context.BehaveDriver()
context.behave_driver.default_wait = 5
Expand Down
2 changes: 1 addition & 1 deletion tests/features/isExisting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Feature: Github test
And check if some elements are existing and others are not

Scenario: open URL
Given I open the url "https://github.com/webdriverio/cucumber-boilerplate"
Given I open the url "https://github.com/spyoungtech/behave-webdriver"
Then I expect that element ".octicon-mark-github" does exist
And I expect that element ".some-other-element" does not exist
4 changes: 0 additions & 4 deletions tests/features/sampleSnippets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Feature: Sample Snippets test
As a developer
I should be able to use given text snippets

#@Isolate
Scenario: open URL
Given the page url is not "http://webdriverjs.christian-bromann.com/"
And I open the url "http://webdriverjs.christian-bromann.com/"
Expand Down Expand Up @@ -146,7 +145,6 @@ Feature: Sample Snippets test
And I expect that element ".red" is not 103px broad
And I expect that element ".red" is not 103px tall

# For some reason this test is failing when running it in the Travis VM
@Pending
Scenario: check offset
Given I open the url "http://webdriverjs.christian-bromann.com/"
Expand All @@ -165,7 +163,6 @@ Feature: Sample Snippets test
When I click on the element ".checkbox_notselected"
Then I expect that checkbox ".checkbox_notselected" is checked

# This will fail in PhantoJS due to a security warning
@Pending
Scenario: set / read cookie
Given I open the url "http://webdriverjs.christian-bromann.com/"
Expand All @@ -175,7 +172,6 @@ Feature: Sample Snippets test
And I expect that cookie "test" contains "test123"
And I expect that cookie "test" not contains "test1234"

# This will fail in PhantoJS due to a security warning
@Pending
Scenario: delete cookie
Given I open the url "http://webdriverjs.christian-bromann.com/"
Expand Down
2 changes: 1 addition & 1 deletion tests/features/transformation_fixture.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Feature: Using a transformation fixture from feature file
Scenario: transform step from environment variable
Given the base url is "{ENV_BASE_URL}"
When I open the site "/page.html"
Then I expect that the url is "http://127.0.0.1:8000/page.html"
Then I expect that the url is "{ENV_BASE_URL}page.html"
2 changes: 1 addition & 1 deletion tests/features/wait.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Test waiting for actions
I want to be able to test if delayed actions are being performed

Background:
Given I open the url "http://localhost:8000/"
Given I open the site "/"
And I pause for 1000ms

Scenario: Test if element becomes checked after 2000 ms
Expand Down