-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
915b897
commit a0b15fc
Showing
14 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import unittest | ||
from selenium.webdriver.support import expected_conditions | ||
from selenium import webdriver | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
|
||
|
||
class GoogleSearch(unittest.TestCase): | ||
def setUp(self): | ||
self.driver = webdriver.Firefox() | ||
self.driver.implicitly_wait(30) | ||
self.base_url = "https://www.google.com/" | ||
|
||
def test_google_search(self): | ||
driver = self.driver | ||
driver.get(self.base_url) | ||
|
||
element = driver.find_element_by_idname("q") | ||
element.clear() | ||
element.send_keys("Selenium testing tools cookbook") | ||
element.submit() | ||
|
||
WebDriverWait(driver, 30)\ | ||
.until(expected_conditions.title_contains("Selenium testing tools cookbook")) | ||
self.assertEqual(driver.title, "Selenium testing tools cookbook - Google Search") | ||
|
||
def tearDown(self): | ||
self.driver.quit() | ||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=2, warnings="ignore") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from selenium import webdriver | ||
from array import * | ||
import time, unittest | ||
|
||
class JQuerySelectorTest (unittest.TestCase): | ||
def setUp(self) : | ||
self.driver = webdriver.Chrome() | ||
self.driver.get("http://dl.dropbox.com/u/55228056/Locators.html") | ||
|
||
def test_jquery_selector(self): | ||
driver = self.driver | ||
|
||
#Expected list of selected Checkbox | ||
exp_checked = ["user128_admin", "user220_browser"] | ||
act_checked = [] | ||
|
||
elements = driver.execute_script("return jQuery.find(':checked')") | ||
|
||
#Verify two Checkbox are selected | ||
self.assertEquals(2, len(elements)) | ||
|
||
#Verify correct Checkbox are selected | ||
for element in elements: | ||
act_checked.append(element.get_attribute("id")) | ||
|
||
self.assertEquals(act_checked, exp_checked) | ||
|
||
def tearDown(self): | ||
self.driver.close() | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import csv, unittest | ||
from ddt import ddt, data, unpack | ||
from selenium import webdriver | ||
|
||
def get_data(file_name): | ||
# create an empty list to store rows | ||
rows = [] | ||
# open the CSV file | ||
data_file = open(file_name, "rb") | ||
# create a CSV Reader from CSV file | ||
reader = csv.reader(data_file) | ||
# skip the headers | ||
next(reader, None) | ||
# add rows from reader to list | ||
for row in reader: | ||
rows.append(row) | ||
return rows | ||
|
||
|
||
@ddt | ||
class SearchCsvDDT(unittest.TestCase): | ||
def setUp(self): | ||
# create a new Firefox session | ||
self.driver = webdriver.Firefox() | ||
self.driver.implicitly_wait(30) | ||
self.driver.maximize_window() | ||
|
||
# navigate to the BMI Calculator page | ||
self.driver.get("http://bit.ly/1zdNrFZ") | ||
|
||
# get the data from specified csv file by calling the get_data function | ||
@data(*get_data("testdata.csv")) | ||
@unpack | ||
def test_bmi_calc(self, height, weight, bmi, category): | ||
driver = self.driver | ||
|
||
height_field = driver.find_element_by_name("heightCMS") | ||
height_field.clear() | ||
height_field.send_keys(height) | ||
|
||
weight_field = driver.find_element_by_name("weightKg") | ||
weight_field.clear() | ||
weight_field.send_keys(weight) | ||
|
||
calculate_button = driver.find_element_by_id("Calculate") | ||
calculate_button.click() | ||
|
||
bmi_label = driver.find_element_by_name("bmi") | ||
bmi_category_label = driver.find_element_by_name("bmi_category") | ||
|
||
self.assertEqual(str(bmi), bmi_label.get_attribute("value")) | ||
self.assertEqual(str(category), bmi_category_label.get_attribute("value")) | ||
|
||
def tearDown(self): | ||
# close the browser window | ||
self.driver.quit() | ||
|
||
if __name__ == '__main__': | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import unittest | ||
from ddt import ddt, data, unpack | ||
from selenium import webdriver | ||
|
||
|
||
@ddt | ||
class BmiCalcDDT(unittest.TestCase): | ||
def setUp(self): | ||
# create a new Firefox session | ||
self.driver = webdriver.Firefox() | ||
self.driver.implicitly_wait(30) | ||
self.driver.maximize_window() | ||
|
||
# navigate to the BMI Calculator page | ||
self.driver.get("http://bit.ly/1zdNrFZ") | ||
|
||
# specify test data using @data decorator | ||
@data(("160", "45", "17.6", "Underweight"), | ||
("168", "70", "24.8", "Normal"), | ||
("181", "89", "27.2", "Overweight")) | ||
@unpack | ||
def test_bmi_calc(self, height, weight, bmi, category): | ||
driver = self.driver | ||
|
||
height_field = driver.find_element_by_name("heightCMS") | ||
height_field.clear() | ||
height_field.send_keys(height) | ||
|
||
weight_field = driver.find_element_by_name("weightKg") | ||
weight_field.clear() | ||
weight_field.send_keys(weight) | ||
|
||
calculate_button = driver.find_element_by_id("Calculate") | ||
calculate_button.click() | ||
|
||
bmi_label = driver.find_element_by_name("bmi") | ||
bmi_category_label = driver.find_element_by_name("bmi_category") | ||
|
||
self.assertEqual(bmi, bmi_label.get_attribute("value")) | ||
self.assertEqual(category, bmi_category_label.get_attribute("value")) | ||
|
||
def tearDown(self): | ||
# close the browser window | ||
self.driver.quit() | ||
|
||
if __name__ == '__main__': | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
height, weight, bmi, category | ||
160, 45, 17.6, Underweight | ||
168, 70, 24.8, Normal | ||
181, 89, 27.2, Overweight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class BmiCalcPage(object): | ||
def __init__(self, driver): | ||
self._driver = driver | ||
self._url = 'http://cookbook.seleniumacademy.com/bmicalculator.html' | ||
self._title = 'BMI Calculator' | ||
|
||
@property | ||
def is_loaded(self): | ||
return self._driver.title == self._title | ||
|
||
@property | ||
def bmi(self): | ||
bmi_field = self._driver.find_element_by_id('bmi') | ||
return bmi_field.get_attribute('value') | ||
|
||
@property | ||
def bmi_category(self): | ||
bmi_category_field = self._driver.find_element_by_id('bmi_category') | ||
return bmi_category_field.get_attribute('value') | ||
|
||
def open(self): | ||
self._driver.get(self._url) | ||
|
||
def calculate(self, height, weight): | ||
height_field = self._driver.find_element_by_id('heightCMS') | ||
weight_field = self._driver.find_element_by_id('weightKg') | ||
calc_button = self._driver.find_element_by_id('Calculate') | ||
|
||
height_field.send_keys(height) | ||
weight_field.send_keys(weight) | ||
calc_button.click() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import unittest | ||
from selenium.webdriver.chrome.webdriver import WebDriver | ||
from bmi_calc_page import bmicalcpage | ||
|
||
class BmiCalcTest(unittest.TestCase): | ||
def testCalc(self): | ||
driver = WebDriver() | ||
bmi_calc = bmicalcpage(driver) | ||
bmi_calc.open() | ||
self.assertEqual(True, bmi_calc.is_loaded) | ||
bmi_calc.calculate('181','80') | ||
self.assertEqual('24.4', bmi_calc.bmi) | ||
self.assertEqual('Normal', bmi_calc.bmi_category) | ||
driver.close() | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'UNMESH' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from selenium import webdriver | ||
|
||
|
||
def before_all(context): | ||
context.driver = webdriver.Chrome() | ||
|
||
def after_all(context): | ||
context.driver.quit() |
25 changes: 25 additions & 0 deletions
25
python/chapter11/fundtransfer/features/fundtransfer.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Feature: Customer Transfer's Fund | ||
As a customer, | ||
I want to transfer funds | ||
so that I can send money to my friends and family | ||
|
||
Scenario: Valid Payee | ||
Given the user is on Fund Transfer Page | ||
When he enters Jim as payee name | ||
And he enters 100 as amount | ||
And he Submits request for Fund Transfer | ||
Then ensure the fund transfer is complete with $100 transferred successfully to Jim!! message | ||
|
||
Scenario: Invalid Payee | ||
Given the user is on Fund Transfer Page | ||
When he enters Unmesh as payee name | ||
And he enters 100 as amount | ||
And he Submits request for Fund Transfer | ||
Then ensure a transaction failure message Transfer failed!! 'Unmesh' is not registered in your List of Payees is displayed | ||
|
||
Scenario: Account is overdrawn past the overdraft limit | ||
Given the user is on Fund Transfer Page | ||
When he enters Tim as payee name | ||
And he enters 1000000 as amount | ||
And he Submits request for Fund Transfer | ||
Then ensure a transaction failure message Transfer failed!! account cannot be overdrawn is displayed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from behave import * | ||
|
||
|
||
@given('the user is on Fund Transfer Page') | ||
def step_user_is_on_fund_transfer_page(context): | ||
context.driver.get("http://cookbook.seleniumacademy.com/fundTransfer.html") | ||
|
||
@when('he enters {name} as payee name') | ||
def step_he_enters_payee_name(context, name): | ||
context.driver.find_element_by_id("payee").send_keys(name) | ||
|
||
@when('he enters {amount} as amount') | ||
def step_he_enters_amount(context, amount): | ||
context.driver.find_element_by_id("amount").send_keys(amount) | ||
|
||
@when('he Submits request for Fund Transfer') | ||
def step_he_enters_amount(context): | ||
context.driver.find_element_by_id("transfer").click() | ||
|
||
@then('ensure the fund transfer is complete with {text} message') | ||
def step_ensure_fund_transfer_is_complete(context, text): | ||
assert context.driver.find_element_by_id("message").text == text | ||
|
||
@then('ensure a transaction failure message {text} is displayed') | ||
def step_ensure_fund_transfer_is_complete(context, text): | ||
assert context.driver.find_element_by_id("message").text == text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import glob | ||
from subprocess import Popen | ||
|
||
|
||
tests = glob.glob('test*.py') | ||
processes = [Popen('python %s' % test, shell=True) for test in tests] | ||
|
||
for process in processes: | ||
process.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import unittest | ||
from selenium import webdriver | ||
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
|
||
|
||
class OnInternetExplorer(unittest.TestCase): | ||
def setUp(self): | ||
self.driver = webdriver.Remote( | ||
command_executor='http://localhost:4444/wd/hub', | ||
desired_capabilities=DesiredCapabilities.FIREFOX) | ||
|
||
def test_Google_Search_IE(self): | ||
driver = self.driver | ||
driver.get("http://www.google.com") | ||
inputElement = driver.find_element_by_name("q") | ||
inputElement.send_keys("Cheese!") | ||
inputElement.submit() | ||
WebDriverWait(driver, 20).until(lambda driver: driver.title.lower().startswith("cheese!")) | ||
self.assertEqual("cheese! - Google Search", driver.title) | ||
|
||
def tearDown(self): | ||
self.driver.quit() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import unittest | ||
from selenium import webdriver | ||
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | ||
|
||
from selenium.webdriver.support.ui import WebDriverWait | ||
|
||
|
||
class OnFirefox(unittest.TestCase): | ||
def setUp(self): | ||
self.driver = webdriver.Remote( | ||
command_executor='http://localhost:4444/wd/hub', | ||
desired_capabilities=DesiredCapabilities.INTERNETEXPLORER) | ||
|
||
def test_Google_Search_FF(self): | ||
driver = self.driver | ||
driver.get("http://www.google.com") | ||
inputElement = driver.find_element_by_name("q") | ||
inputElement.send_keys("Cheese!") | ||
inputElement.submit() | ||
WebDriverWait(driver, 20).until(lambda driver: driver.title.lower().startswith("cheese!")) | ||
self.assertEqual("cheese! - Google Search", driver.title) | ||
|
||
def tearDown(self): | ||
self.driver.quit() | ||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |