Skip to content
Draft
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
49 changes: 24 additions & 25 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def browser_init(context, test_name):
:param context: Behave context
:param test_name: scenario.name
"""
# service = Service('/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
# service = Service('./chromedriver')
# service = Service('/Users/svetlanalevinsohn/JobEasy/12-python-selenium-automation/geckodriver')
# context.driver = webdriver.Chrome(service=service)
# context.driver = webdriver.Firefox(service=service)
Expand All @@ -31,31 +31,30 @@ def browser_init(context, test_name):
# chrome_options=options,
# service=service
# )
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("window-size=1400,2100")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')

### EventFiringWebDriver - log file ###
### for drivers ###
# context.driver = EventFiringWebDriver(
# webdriver.Chrome(service=service),
# MyListener()
# )
# for headless mode ###
# context.driver = EventFiringWebDriver(webdriver.Chrome(chrome_options = options), MyListener())
context.driver = webdriver.Chrome(chrome_options=chrome_options)

# for browerstack ###
# Register for BrowserStack, then grab it from https://www.browserstack.com/accounts/settings
bs_user = ''
bs_key = ''

desired_cap = {
'browserName': 'Firefox',
'bstack:options': {
'os': 'Windows',
'osVersion': '10',
'sessionName': test_name
}
}
url = f'http://{bs_user}:{bs_key}@hub-cloud.browserstack.com/wd/hub'
context.driver = webdriver.Remote(url, desired_capabilities=desired_cap)
# bs_user = ''
# bs_key = ''

# desired_cap = {
# 'browserName': 'Firefox',
# 'bstack:options': {
# 'os': 'Windows',
# 'osVersion': '10',
# 'sessionName': test_name
# }
# }
# url = f'http://{bs_user}:{bs_key}@hub-cloud.browserstack.com/wd/hub'
# context.driver = webdriver.Remote(url, desired_capabilities=desired_cap)

context.driver.maximize_window()
context.driver.implicitly_wait(5)
Expand All @@ -65,13 +64,13 @@ def browser_init(context, test_name):


def before_scenario(context, scenario):
# print('\nStarted scenario: ', scenario.name)
print('\nStarted scenario: ', scenario.name)
logger.info(f'Started scenario: {scenario.name}')
browser_init(context, scenario.name)


def before_step(context, step):
# print('\nStarted step: ', step)
print('\nStarted step: ', step)
logger.info(f'Started step: {step}')


Expand All @@ -85,5 +84,5 @@ def after_step(context, step):


def after_scenario(context, feature):
context.driver.delete_all_cookies()
# context.driver.delete_all_cookies()
context.driver.quit()
2 changes: 2 additions & 0 deletions pages/base_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from support.logger import logger
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep


class Page:
Expand All @@ -12,6 +13,7 @@ def __init__(self, driver):

def open_url(self, url):
self.driver.get(url)
sleep(2)

def find_element(self, *locator):
return self.driver.find_element(*locator)
Expand Down
34 changes: 34 additions & 0 deletions run_selenium_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# Set the BASE_DIR variable to the current working directory
# (this is how you set variables in shell)
BASE_DIR=$(pwd)
# Create allure-test-results folder for allure files
mkdir -p $BASE_DIR/allure-test-results

# Install all dependencies from requirements.txt
pip3 install --no-cache-dir -r requirements.txt

# Run the tests:
behave -f allure_behave.formatter:AllureFormatter -o results/ features/tests/bestsellers.feature

# This line sets the EXIT_CODE variable to the exit status of the previous command.
EXIT_CODE=$?

# Generate allure report:
allure generate -c ./results/ -o $BASE_DIR/allure-test-results
sleep 10 # wait for report to generate

# Compress allure report to allure-results.tgz file
cd $BASE_DIR/allure-test-results && tar czvf $BASE_DIR/allure-test-results/allure-results.tgz *

# Send allure-results.tgz to the cloud
# This is OPTIONAL! You'll need to set up your cloud storage first,
# for example via google: https://stackoverflow.com/a/75541409/7746992
#curl -X POST -T $BASE_DIR/allure-test-results/allure-results.tgz \
# -H "Authorization: Bearer YOUR_TOKEN" \
# -H "Content-Type: application/json" \
# "https://storage.googleapis.com/upload/storage/v1/b/lana-storage/o?uploadType=media&name=allure-results.tgz"

# Exit the script with the exit status of the previous command
exit $EXIT_CODE
37 changes: 37 additions & 0 deletions webtests_chrome.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Set the base image for this Dockerfile to the official selenium/standalone-chrome image,
# which contains a standalone Selenium server and Chrome browser.
FROM selenium/standalone-chrome

# Change the user to root (gives admin privileges)
USER root

# The WORKDIR instruction in a Dockerfile sets the working directory.
# This means that any file operations or commands that are executed in the container
# will be relative to the directory specified by the WORKDIR instruction.
# Any subsequent RUN, CMD, COPY, etc. instructions
# will be executed in the //usr/src/13-python-selenium-automation directory.
WORKDIR /usr/src/13-python-selenium-automation

# Install python3-pip package
RUN apt-get -y update
RUN apt-get -y install -y software-properties-common
RUN apt-get -y install python3-pip

# Download Allure commandline from GitHub and install it
RUN curl -o allure-2.14.0.tgz -Ls https://github.com/allure-framework/allure2/releases/download/2.14.0/allure-2.14.0.tgz
RUN tar -zxvf allure-2.14.0.tgz -C /opt/
RUN ln -s /opt/allure-2.14.0/bin/allure /usr/bin/allure
# Verify Allure installed
RUN allure --version

# Copy all the files from the current directory (the directory containing the Dockerfile)
# to the working directory inside the container.
COPY . .

# chmod +x command makes the run_selenium_tests.sh file executable
# (it changes the permission of a file)
RUN chmod +x ./run_selenium_tests.sh

# CMD command specifies the command to run when a container is started,
# which in this case is ./run_selenium_tests.sh.
CMD ["./run_selenium_tests.sh"]