Skip to content

Commit

Permalink
day6 BDD
Browse files Browse the repository at this point in the history
  • Loading branch information
amr1ta committed Aug 25, 2019
1 parent 2e435ad commit 4a4a968
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 0 deletions.
4 changes: 4 additions & 0 deletions day6/FrameworkRunner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python

from behave.__main__ import main as behave_main
behave_main('features')
7 changes: 7 additions & 0 deletions day6/behave.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[behave]
stderr_capture = False
stdout_capture = False

[behave.userdata]
browser = chrome
homepage_url = https://en.wikipedia.org/wiki/Main_Page
14 changes: 14 additions & 0 deletions day6/features/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from pages.base_page import BasePage


def before_all(context):
browser = context.config.userdata['browser']
if browser == "chrome":
driver = BasePage(webdriver.Chrome(ChromeDriverManager().install()))
context.driver = driver
context.homepage_url = context.config.userdata['homepage_url']

def after_all(context):
context.driver.quit()
33 changes: 33 additions & 0 deletions day6/features/steps/stepDefinitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from behave import given, when, then
from hamcrest import assert_that, equal_to

from pages.locators import *
from pages.home_page import HomePage
from pages.search_page import SearchPage


@given("User is on wikipedia Homepage")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
context.driver.open(context.homepage_url)


@when('User searches "{word}"')
def step_impl(context, word):
"""
:type context: behave.runner.Context
"""
homepage = HomePage(context.driver)
homepage.set_search_query(word)
homepage.search()


@then('Title of the page should be "{word}"')
def step_impl(context, word):
"""
:type context: behave.runner.Context
"""
search_page = SearchPage(context.driver)
assert_that(search_page.heading_text(), equal_to(word))
6 changes: 6 additions & 0 deletions day6/features/wikipedia.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Wikipedia landing page feature

Scenario: Launch wikipedia application
Given User is on wikipedia Homepage
When User searches "Design Pattern"
Then Title of the page should be "Design pattern"
Empty file added day6/pages/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions day6/pages/base_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Base Page
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class BasePage():
def __init__(self, driver):
self._driver = driver
self._timeout = 10
self._driver_wait = WebDriverWait(self._driver, self._timeout)

def open(self, url):
self._driver.get(url)
self._driver.maximize_window()

# Add Explicit Wait to find_element API
def find_element(self, *locator):
return self._driver_wait.until(EC.visibility_of_element_located(locator))

def quit(self):
return self._driver.quit()
10 changes: 10 additions & 0 deletions day6/pages/home_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pages.base_page import BasePage
from pages.locators import HomePageLocators

class HomePage(BasePage):

def set_search_query(self, query):
self.find_element(*HomePageLocators.SEARCH_CONTAINER).send_keys(query)

def search(self):
self.find_element(*HomePageLocators.SEARCH_BUTTON).click()
8 changes: 8 additions & 0 deletions day6/pages/locators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from selenium.webdriver.common.by import By

class HomePageLocators():
SEARCH_CONTAINER = (By.ID, "searchInput")
SEARCH_BUTTON = (By.ID, "searchButton")

class SearchPageLocators():
HEADING = (By.ID, "firstHeading")
7 changes: 7 additions & 0 deletions day6/pages/search_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pages.base_page import BasePage
from pages.locators import SearchPageLocators

class SearchPage(BasePage):

def heading_text(self):
return self.find_element(*SearchPageLocators.HEADING).text

0 comments on commit 4a4a968

Please sign in to comment.