├── .gitignore ├── README.md ├── features ├── __init__.py ├── environment.py ├── steps │ ├── __init__.py │ └── product_search.py └── tests │ ├── __init__.py │ └── product_search.feature ├── requirements.txt └── sample_script.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # PyBuilder 51 | target/ 52 | 53 | # pyenv 54 | .python-version 55 | 56 | # Environments 57 | .env 58 | .venv 59 | env/ 60 | venv/ 61 | ENV/ 62 | env.bak/ 63 | venv.bak/ 64 | 65 | # Spyder project settings 66 | .spyderproject 67 | .spyproject 68 | 69 | # Rope project settings 70 | .ropeproject 71 | 72 | # mkdocs documentation 73 | /site 74 | 75 | # mypy 76 | .mypy_cache/ 77 | 78 | # idea 79 | .idea/ 80 | *.iws/ 81 | 82 | # logs 83 | *.log 84 | 85 | # app files 86 | app_binaries/ 87 | *.apk 88 | *.app 89 | *.ipa 90 | 91 | .DS_Store 92 | 93 | /features/test_results/* 94 | 95 | # Screenshots 96 | *.png 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Careerist Test Automation repository 2 | 3 | written in 4 | ### Python 3, Behave 5 | -------------------------------------------------------------------------------- /features/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jobeasy-team/python-selenium-automation/0180ad2ee428ba86c32cc0ca64ab53c1f991f44d/features/__init__.py -------------------------------------------------------------------------------- /features/environment.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | 4 | def browser_init(context): 5 | """ 6 | :param context: Behave context 7 | """ 8 | context.driver = webdriver.Chrome() 9 | # context.browser = webdriver.Safari() 10 | # context.browser = webdriver.Firefox() 11 | 12 | context.driver.maximize_window() 13 | context.driver.implicitly_wait(4) 14 | 15 | 16 | def before_scenario(context, scenario): 17 | print('\nStarted scenario: ', scenario.name) 18 | browser_init(context) 19 | 20 | 21 | def before_step(context, step): 22 | print('\nStarted step: ', step) 23 | 24 | 25 | def after_step(context, step): 26 | if step.status == 'failed': 27 | print('\nStep failed: ', step) 28 | 29 | 30 | def after_scenario(context, feature): 31 | context.driver.delete_all_cookies() 32 | context.driver.quit() 33 | -------------------------------------------------------------------------------- /features/steps/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jobeasy-team/python-selenium-automation/0180ad2ee428ba86c32cc0ca64ab53c1f991f44d/features/steps/__init__.py -------------------------------------------------------------------------------- /features/steps/product_search.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.by import By 2 | from behave import given, when, then 3 | from time import sleep 4 | 5 | 6 | SEARCH_INPUT = (By.NAME, 'q') 7 | SEARCH_SUBMIT = (By.NAME, 'btnK') 8 | 9 | 10 | @given('Open Google page') 11 | def open_google(context): 12 | context.driver.get('https://www.google.com/') 13 | 14 | 15 | @when('Input {search_word} into search field') 16 | def input_search(context, search_word): 17 | search = context.driver.find_element(*SEARCH_INPUT) 18 | search.clear() 19 | search.send_keys(search_word) 20 | sleep(4) 21 | 22 | 23 | @when('Click on search icon') 24 | def click_search_icon(context): 25 | context.driver.find_element(*SEARCH_SUBMIT).click() 26 | sleep(1) 27 | 28 | 29 | @then('Product results for {search_word} are shown') 30 | def verify_found_results_text(context, search_word): 31 | assert search_word.lower() in context.driver.current_url.lower(), f"Expected query not in {context.driver.current_url.lower()}" 32 | -------------------------------------------------------------------------------- /features/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jobeasy-team/python-selenium-automation/0180ad2ee428ba86c32cc0ca64ab53c1f991f44d/features/tests/__init__.py -------------------------------------------------------------------------------- /features/tests/product_search.feature: -------------------------------------------------------------------------------- 1 | # Created by Svetlana at 4/4/19 2 | Feature: Test Scenarios for Search functionality 3 | 4 | Scenario: User can search for a product 5 | Given Open Google page 6 | When Input Dress into search field 7 | And Click on search icon 8 | Then Product results for Dress are shown 9 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | behave 2 | selenium -------------------------------------------------------------------------------- /sample_script.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | from selenium import webdriver 3 | from selenium.webdriver.common.by import By 4 | 5 | # init driver 6 | driver = webdriver.Chrome() 7 | driver.maximize_window() 8 | 9 | # open the url 10 | driver.get('https://www.google.com/') 11 | 12 | search = driver.find_element(By.NAME, 'q') 13 | search.clear() 14 | search.send_keys('Dress') 15 | 16 | # wait for 4 sec 17 | sleep(4) 18 | 19 | # click search 20 | driver.find_element(By.NAME, 'btnK').click() 21 | 22 | # verify 23 | assert 'dress' in driver.current_url.lower(), f"Expected query not in {driver.current_url.lower()}" 24 | print('Test Passed') 25 | 26 | driver.quit() 27 | --------------------------------------------------------------------------------