First Commit
|
@ -0,0 +1,5 @@
|
|||
.cache/
|
||||
.idea/
|
||||
*__pycache__/
|
||||
*.log
|
||||
*.pytest_cache/
|
|
@ -0,0 +1,30 @@
|
|||
from selenium import webdriver
|
||||
|
||||
class WebDriverFactory():
|
||||
def __init__(self,browser):
|
||||
self.browser = browser
|
||||
|
||||
def get_browser_instance(self):
|
||||
if self.browser == "FF":
|
||||
driver = webdriver.Firefox()
|
||||
|
||||
elif self.browser == "Chrome":
|
||||
driver = webdriver.Chrome()
|
||||
|
||||
elif self.browser == "IE":
|
||||
driver = webdriver.Ie()
|
||||
|
||||
else:
|
||||
driver = webdriver.Chrome()
|
||||
|
||||
|
||||
baseUrl = "http://live.demoguru99.com/index.php/"
|
||||
driver.delete_all_cookies()
|
||||
driver.maximize_window()
|
||||
driver.implicitly_wait(15)
|
||||
driver.get(baseUrl)
|
||||
|
||||
return driver
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
from base.selenium_driver import SeleniumDriver
|
||||
from utilities.util import Utilities
|
||||
|
||||
|
||||
class BasePage(SeleniumDriver):
|
||||
def __init__(self,driver):
|
||||
super(BasePage, self).__init__(driver)
|
||||
self.driver = driver
|
||||
self.util = Utilities()
|
||||
|
||||
|
||||
def verify_page_title(self, titleToVerify):
|
||||
actualTitle = self.getTitle()
|
||||
return self.util.verify_text_contains(actualText = actualTitle, expectedText=titleToVerify)
|
|
@ -0,0 +1,535 @@
|
|||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import *
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support.select import Select
|
||||
from utilities.customlogger import custom_logger
|
||||
import logging
|
||||
import time
|
||||
import os
|
||||
from selenium.webdriver import ActionChains
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from traceback import print_stack
|
||||
from selenium.webdriver.support.color import Color
|
||||
|
||||
|
||||
class SeleniumDriver():
|
||||
cl = custom_logger(logging.INFO)
|
||||
|
||||
def __init__(self, driver):
|
||||
self.driver = driver
|
||||
|
||||
self.actions = ActionChains(self.driver)
|
||||
|
||||
def ByType(self, locatorType):
|
||||
locatorType = locatorType.lower()
|
||||
|
||||
if locatorType == "id":
|
||||
return By.ID
|
||||
elif locatorType == "xpath":
|
||||
return By.XPATH
|
||||
elif locatorType == "css":
|
||||
return By.CSS_SELECTOR
|
||||
elif locatorType == "link":
|
||||
return By.LINK_TEXT
|
||||
elif locatorType == "partial link":
|
||||
return By.PARTIAL_LINK_TEXT
|
||||
elif locatorType == "name":
|
||||
return By.NAME
|
||||
elif locatorType == "tag":
|
||||
return By.TAG_NAME
|
||||
elif locatorType == "class":
|
||||
return By.CLASS_NAME
|
||||
|
||||
else:
|
||||
self.cl.info("Invalid Locatortype " + str(locatorType))
|
||||
|
||||
def findElement(self, locator, locatorType):
|
||||
element = None
|
||||
try:
|
||||
bytype = self.ByType(locatorType)
|
||||
element = self.driver.find_element(bytype, locator)
|
||||
self.driver.execute_script("arguments[0].scrollIntoView(true);", element);
|
||||
self.driver.execute_script("arguments[0].style.border='3px solid red'", element);
|
||||
self.cl.info(
|
||||
"Element found with locatorType : " + str(locatorType) + " & locator : " + str(locator) + str(element))
|
||||
return element
|
||||
except:
|
||||
self.cl.info(
|
||||
"Element could not be found with type : " + str(locatorType) + " and locator : " + str(locator))
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def findElements(self, locator, locatorType):
|
||||
element = []
|
||||
try:
|
||||
bytype = self.ByType(locatorType)
|
||||
element = self.driver.find_elements(bytype, locator)
|
||||
self.cl.info("Element found with locatorType : " + str(locatorType) + "& locator : " + str(locator))
|
||||
return element
|
||||
except:
|
||||
self.cl.info(
|
||||
"Element could not be found with locatortype : " + str(locatorType) + " and locator : " + str(locator))
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def get_element_dropdown_value(self, locator, locatorType, selectType, value):
|
||||
element = None
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
|
||||
sel = Select(element)
|
||||
if selectType == "Value":
|
||||
sel.select_by_value(value)
|
||||
self.cl.info("Selected element with Name " + str(value) + " from the drop down using Value")
|
||||
|
||||
elif selectType == "text":
|
||||
sel.select_by_visible_text(value)
|
||||
self.cl.info("Selected element with value " + str(value) + " from the drop down using Visible Text")
|
||||
|
||||
elif selectType == "index":
|
||||
sel.select_by_index(value)
|
||||
self.cl.info("Selected element with index " + str(value) + " from the drop down using Index position")
|
||||
|
||||
except:
|
||||
self.cl.info("Unable to select element from the dropdown")
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def elementClick(self, locator, locatorType):
|
||||
element = None
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
element.click()
|
||||
self.cl.info("Clicked on Element : " + str(element))
|
||||
|
||||
except ElementClickInterceptedException:
|
||||
self.cl.info("Unable to click the element: " + locator)
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def elementSend(self, locator, locatorType, message):
|
||||
element = None
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
element.clear()
|
||||
element.send_keys(message)
|
||||
self.cl.info("Text : " + str(message) + " entered on locator: " + locator)
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to send the message on locator: " + locator)
|
||||
print_stack()
|
||||
|
||||
def getTitle(self):
|
||||
return self.driver.title
|
||||
|
||||
def getText(self, locator, locatorType):
|
||||
element = None
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
element_text = element.text
|
||||
self.cl.info("Text of the element : " + locator + " is " + element_text)
|
||||
return element_text
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to find the text for element : " + locator)
|
||||
print_stack()
|
||||
|
||||
def getTextElementList(self, locator, locatorType):
|
||||
elementText = []
|
||||
elementText2 = []
|
||||
try:
|
||||
element = self.findElements(locator, locatorType)
|
||||
for item in element:
|
||||
itemtext = item.text
|
||||
elementText.append(itemtext)
|
||||
|
||||
elementText2 = list(filter(None, elementText))
|
||||
self.cl.info(elementText2)
|
||||
return elementText2
|
||||
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to return text for elements")
|
||||
print_stack()
|
||||
|
||||
def getAttribute(self, locator, locatorType, attributeType):
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
elementAttribute = element.get_attribute(attributeType)
|
||||
self.cl.info("Value of Attribute :: " + attributeType + " is " + str(elementAttribute))
|
||||
return elementAttribute
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to find the value of attribute for element : " + locator)
|
||||
print_stack()
|
||||
|
||||
def getAttributelist(self, locator, locatorType, attributeType):
|
||||
element_attribute = []
|
||||
try:
|
||||
element = self.findElements(locator, locatorType)
|
||||
for item in element:
|
||||
elementAttribute = item.get_attribute(attributeType)
|
||||
element_attribute.append(elementAttribute)
|
||||
self.cl.info("Value of Attribute :: " + attributeType + " is " + elementAttribute)
|
||||
return element_attribute
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to find the value of attribute for element : " + locator)
|
||||
print_stack()
|
||||
|
||||
def get_value_of_css_property(self, locator, locatorType, attributeType):
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
cssAttributeProperty = element.value_of_css_property(property_name=attributeType)
|
||||
self.cl.info("Value of CSS Attribute :: " + attributeType + " is " + cssAttributeProperty)
|
||||
if attributeType == 'Color':
|
||||
formatted_name = Color.from_string(cssAttributeProperty).hex
|
||||
self.cl.info("Value of CSS Attribute :: " + attributeType + " in HEX format is " + cssAttributeProperty)
|
||||
return formatted_name
|
||||
else:
|
||||
return cssAttributeProperty
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to find the value of attribute for element : " + locator)
|
||||
print_stack()
|
||||
|
||||
def explicitwait(self, locator, locatorType, time, poll):
|
||||
try:
|
||||
bytype = self.ByType(locatorType)
|
||||
wait = WebDriverWait(self.driver, timeout=time, poll_frequency=poll,
|
||||
ignored_exceptions=[ElementNotInteractableException, ElementNotVisibleException,
|
||||
NoSuchElementException, TimeoutException,
|
||||
StaleElementReferenceException, ElementClickInterceptedException])
|
||||
self.cl.info("Waiting to click on element : " + locator + "for time " + str(time) + "sec")
|
||||
element = wait.until(EC.element_to_be_clickable((bytype, locator)))
|
||||
self.cl.info("Element is Available for action")
|
||||
|
||||
except:
|
||||
self.cl.info("Unable to find the element")
|
||||
print_stack()
|
||||
|
||||
def explicit_wait_for_iframe(self, locator, index, time, poll):
|
||||
try:
|
||||
|
||||
wait = WebDriverWait(self.driver, timeout=time, poll_frequency=poll,
|
||||
ignored_exceptions=[NoSuchFrameException, NoSuchElementException, TimeoutException])
|
||||
self.cl.info("Waiting to find : " + locator + "with index position:: " + str(index) + "for time " + str(
|
||||
time) + "sec")
|
||||
element = wait.until(
|
||||
EC.frame_to_be_available_and_switch_to_it((self.driver.find_elements_by_tag_name(locator)[index])))
|
||||
self.cl.info("iFrame is Available for switching")
|
||||
|
||||
except TimeoutException:
|
||||
self.cl.info("Unable to find the element")
|
||||
|
||||
def isElementPresent(self, locator, locatorType):
|
||||
try:
|
||||
element = self.findElements(locator, locatorType)
|
||||
self.cl.info(element)
|
||||
if len(element) > 0:
|
||||
self.cl.info("Element with locator " + str(locator) + "is present")
|
||||
return True
|
||||
else:
|
||||
self.cl.info("Element with locator " + str(locator) + "is not present")
|
||||
return False
|
||||
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to find element")
|
||||
print_stack()
|
||||
|
||||
def elementclear(self, locator, locatorType):
|
||||
element = None
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
element.clear()
|
||||
self.cl.info("Cleared Element : " + str(element))
|
||||
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to find element")
|
||||
print_stack()
|
||||
|
||||
def savescreenshots(self, resultMessage):
|
||||
filename = resultMessage + str(round(time.time() * 10000)) + ".png"
|
||||
screenshotDirectory = "../screenshots/"
|
||||
relativeFilename = screenshotDirectory + filename
|
||||
|
||||
currentDirectory = os.path.dirname(__file__)
|
||||
destinationPath = os.path.join(currentDirectory, relativeFilename)
|
||||
|
||||
destinationFolder = os.path.join(currentDirectory, screenshotDirectory)
|
||||
|
||||
try:
|
||||
if not os.path.exists(destinationFolder):
|
||||
os.makedirs(destinationFolder)
|
||||
self.driver.save_screenshot(destinationPath)
|
||||
self.cl.info("### Screenshot saved at path: " + destinationPath)
|
||||
except:
|
||||
self.cl.warning("### Exception Occured")
|
||||
print_stack()
|
||||
|
||||
def isElementDisplayed(self, locator, locatorType):
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
isDisplayed = element.is_displayed()
|
||||
|
||||
if isDisplayed:
|
||||
self.cl.info("Element is displayed with locator :: " + str(locator))
|
||||
return isDisplayed
|
||||
else:
|
||||
self.cl.info("Element is not displayed with locator :: " + str(locator))
|
||||
return isDisplayed
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.warning("Exception occured while executing isElementDisplayed")
|
||||
print_stack()
|
||||
|
||||
def scrollingVertical(self, direction):
|
||||
direction = direction.lower()
|
||||
try:
|
||||
if direction == "up":
|
||||
self.driver.execute_script("window.scrollBy(0,-1000);")
|
||||
self.cl.info("Scrolling the screen up")
|
||||
|
||||
if direction == "down":
|
||||
self.driver.execute_script("window.scrollBy(0,700);")
|
||||
self.cl.info("Scrolling the screen down")
|
||||
|
||||
except:
|
||||
self.cl.warning("Exception occured when trying to scroll the screen")
|
||||
print_stack()
|
||||
|
||||
def scrollingHorizontal(self, direction):
|
||||
direction = direction.lower()
|
||||
try:
|
||||
if direction == "left":
|
||||
self.driver.execute_script("window.scrollBy(-600,0);")
|
||||
self.cl.info("Scrolling the screen up")
|
||||
|
||||
if direction == "right":
|
||||
self.driver.execute_script("window.scrollBy(1100,0);")
|
||||
self.cl.info("Scrolling the screen down")
|
||||
|
||||
except:
|
||||
self.cl.warning("Exception occured when trying to scroll the screen")
|
||||
print_stack()
|
||||
|
||||
def switch(self, value):
|
||||
try:
|
||||
self.driver.switch_to.frame(value)
|
||||
self.cl.info("Switched to Iframe :: " + str(value))
|
||||
|
||||
except NoSuchFrameException:
|
||||
self.cl.error("Error while switching to Iframe")
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def switchParentFrame(self):
|
||||
try:
|
||||
self.driver.switch_to.parent_frame()
|
||||
except:
|
||||
self.cl.info("Unable to to Parent Frame")
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def switch_default(self):
|
||||
try:
|
||||
self.driver.switch_to.default_content()
|
||||
self.cl.info("Switched to default content")
|
||||
|
||||
except:
|
||||
self.cl.error("Error while switching to Default Content")
|
||||
print_stack()
|
||||
|
||||
def elementSendSpecial(self, locator, locatorType, message):
|
||||
element = None
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
for items in message:
|
||||
element.send_keys(items)
|
||||
self.cl.info("Text : " + message + " entered on locator: " + locator)
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Unable to send the message on locator: " + locator)
|
||||
print_stack()
|
||||
|
||||
def slider(self, locator, locatorType, xcord, ycord):
|
||||
element = None
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
self.actions.drag_and_drop_by_offset(source=element, xoffset=xcord, yoffset=ycord).perform()
|
||||
except:
|
||||
raise Exception
|
||||
self.cl.info("Exception orrcured during sliding")
|
||||
print_stack()
|
||||
|
||||
def double_clickk(self, locator, locatorType):
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
self.actions.double_click(element).perform()
|
||||
self.cl.info("Double Clicked on :: " + str(element))
|
||||
except StaleElementReferenceException:
|
||||
self.cl.info("Exception occured during Double Click")
|
||||
self.cl.info("Double Clicked on :: " + str(element))
|
||||
print_stack()
|
||||
|
||||
def browserRefresh(self):
|
||||
self.driver.refresh()
|
||||
|
||||
def current_handle_window(self):
|
||||
current_window = self.driver.current_window_handle
|
||||
self.cl.info("The current window handle is :: " + str(current_window))
|
||||
return current_window
|
||||
|
||||
def all_window_handles(self):
|
||||
all_handles = self.driver.window_handles
|
||||
self.cl.info("All available Window's are :: " + str(all_handles))
|
||||
return all_handles
|
||||
|
||||
def switching_to_window(self):
|
||||
try:
|
||||
current_window = self.current_handle_window()
|
||||
all_windows = self.all_window_handles()
|
||||
|
||||
for items in all_windows:
|
||||
if items != current_window:
|
||||
self.driver.switch_to.window(items)
|
||||
self.cl.info("Switched to window :: " + str(items))
|
||||
|
||||
except:
|
||||
self.cl.info("Unable to to new window")
|
||||
|
||||
def switch_to_parent_window(self):
|
||||
try:
|
||||
all_windows = self.all_window_handles()
|
||||
|
||||
for items in all_windows:
|
||||
if items == all_windows[0]:
|
||||
self.driver.switch_to.window(items)
|
||||
self.cl.info("Switched to window :: " + str(items))
|
||||
|
||||
except:
|
||||
self.cl.info("Unable to to new window")
|
||||
|
||||
def browserback(self):
|
||||
self.driver.back()
|
||||
|
||||
def browserForward(self):
|
||||
self.driver.forward()
|
||||
|
||||
def action(self):
|
||||
try:
|
||||
self.actions.key_down(Keys.DOWN).key_down(Keys.ENTER).perform()
|
||||
# self.actions.send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()
|
||||
except StaleElementReferenceException:
|
||||
self.actions.key_down(Keys.DOWN).key_down(Keys.ENTER).perform()
|
||||
raise Exception
|
||||
|
||||
def enter(self):
|
||||
try:
|
||||
self.actions.key_down(Keys.ENTER).key_up(Keys.ENTER).perform()
|
||||
self.cl.info("Pressed ENTER")
|
||||
except:
|
||||
self.cl.info("Unable to press ENTER key")
|
||||
raise Exception
|
||||
|
||||
def close_new_window(self):
|
||||
try:
|
||||
self.actions.key_down(Keys.CONTROL).send_keys('W').perform()
|
||||
self.cl.info("Pressing CTRL + W to close the new window")
|
||||
except:
|
||||
self.cl.info("Unable to perform Action :: CTRL + W")
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def js_element_click(self, locator, locatorType):
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
self.driver.execute_script("arguments[0].click();", element);
|
||||
|
||||
except:
|
||||
self.cl.info("Unable to click on element :: " + str(element))
|
||||
raise Exception
|
||||
|
||||
def js_select_list(self, locator, locatorType, message):
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
self.driver.execute_script("arguments[0].removeAttribute('readonly','readonly');", element)
|
||||
element.send_keys(message)
|
||||
self.cl.info("Sending message :: " + str(message) + "locator :: " + str(locator))
|
||||
|
||||
except:
|
||||
self.cl.info("Exception Occured")
|
||||
raise Exception
|
||||
print_stack()
|
||||
|
||||
def stop_page_load(self):
|
||||
try:
|
||||
self.driver.execute_script("return window.stop");
|
||||
self.cl.info("Page load stop")
|
||||
except:
|
||||
self.cl.info("Unable to stop the page load")
|
||||
raise Exception
|
||||
|
||||
# def js_double_click(self,locator,locatorType):
|
||||
# try:
|
||||
# element = self.findElement(locator,locatorType)
|
||||
# self.driver.execute_script("var evt = document.createEvent('MouseEvents');"+
|
||||
# "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);"+
|
||||
# "arguments[0].dispatchEvent(evt);", element);
|
||||
|
||||
# self.cl.info("Double clicked element :: " + str(element))
|
||||
|
||||
# except:
|
||||
# raise Exception
|
||||
# self.cl.info("Unable to Double click element :: " + str(element))
|
||||
|
||||
def right_click(self, locator, locatorType):
|
||||
try:
|
||||
element = self.findElement(locator, locatorType)
|
||||
self.actions.context_click(element).key_down(Keys.DOWN).key_down(Keys.ENTER).perform()
|
||||
|
||||
except:
|
||||
self.cl.info("Unable to right click on element " + str(element))
|
||||
raise Exception
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
firstName,lastName,emailAddress,password,confirmPassword
|
||||
test,four,test@four.com,test12345,test12345
|
|
|
@ -0,0 +1,81 @@
|
|||
from base.selenium_driver import SeleniumDriver
|
||||
from utilities.customlogger import custom_logger
|
||||
import logging
|
||||
import time
|
||||
from pages.mobile_page.mobile_page import MobilePage
|
||||
|
||||
|
||||
class Account(SeleniumDriver):
|
||||
cl = custom_logger(loglevel=logging.INFO)
|
||||
|
||||
def __init__(self,driver):
|
||||
super(Account, self).__init__(driver)
|
||||
self.driver = driver
|
||||
self.mb = MobilePage(self.driver)
|
||||
|
||||
|
||||
#locators
|
||||
_account = "//a/span[text()='Account']"
|
||||
_register = "Register"
|
||||
_firstname = "firstname"
|
||||
_lastname = "lastname"
|
||||
_email_address = "email_address"
|
||||
_password = "password"
|
||||
_confirmation = "confirmation"
|
||||
_checkbox = "is_subscribed"
|
||||
_registeration= "//button[@title='Register']"
|
||||
|
||||
_tv = "TV"
|
||||
_add_to_wishlist = "//a[@title='LG LCD']//following-sibling::div/child::div/ul/li/a"
|
||||
_share_wishlist = "//span[text()='Share Wishlist']"
|
||||
_emailaddress_wishlist = "email_address"
|
||||
_message_wishlist = "message"
|
||||
_message_success_sharelist = "//span[text()='Your Wishlist has been shared.']"
|
||||
|
||||
|
||||
# def click_tv_tab(self):
|
||||
# self.elementClick(self._tv,'link')
|
||||
#
|
||||
# def add_to_wishlist(self):
|
||||
# self.click_tv_tab()
|
||||
# self.elementClick(self._add_to_wishlist,'xpath')
|
||||
# self.elementClick(self._share_wishlist,'xpath')
|
||||
# self.elementSend(self._emailaddress_wishlist,'id','test@two.com')
|
||||
# self.elementSend(self._message_wishlist, 'id', 'Hello Could you please buy for me')
|
||||
# self.elementClick(self._share_wishlist,'xpath')
|
||||
# return self.isElementDisplayed(self._message_success_sharelist,'xpath')
|
||||
|
||||
|
||||
|
||||
def click_account(self):
|
||||
self.elementClick(self._account, 'xpath')
|
||||
self.elementClick(self._register, 'link')
|
||||
|
||||
def fill_registration(self,firstName,lastName,emailAddress,password,confirmPassword):
|
||||
self.elementSend(self._firstname, 'id', firstName)
|
||||
self.elementSend(self._lastname, 'id', lastName)
|
||||
self.elementSend(self._email_address, 'id', emailAddress)
|
||||
self.elementSend(self._password, 'id', password)
|
||||
self.elementSend(self._confirmation, 'id', confirmPassword)
|
||||
|
||||
def checkbox(self,):
|
||||
self.elementClick(self._checkbox, 'id')
|
||||
|
||||
def click_registration_button(self):
|
||||
self.elementClick(self._registeration,'xpath')
|
||||
|
||||
|
||||
def success_message(self,success):
|
||||
_success_message = f"//span[text()='{success}']"
|
||||
return self.isElementDisplayed(_success_message,'xpath')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
from base.base_page import BasePage
|
||||
from utilities.customlogger import custom_logger
|
||||
import logging
|
||||
from utilities.util import Utilities
|
||||
|
||||
|
||||
|
||||
|
||||
class MobilePage(BasePage):
|
||||
cl = custom_logger(logging.INFO)
|
||||
|
||||
def __init__(self,driver):
|
||||
super(MobilePage, self).__init__(driver)
|
||||
self.driver = driver
|
||||
self.utill = Utilities()
|
||||
|
||||
|
||||
#locator
|
||||
_mobile = "MOBILE"
|
||||
_Iphone = "IPHONE"
|
||||
_samsung = "SAMSUNG GALAXY"
|
||||
_sony = "SONY XPERIA"
|
||||
_expected_list1 = ['IPHONE', 'SAMSUNG GALAXY', 'SONY XPERIA']
|
||||
_expected_list2 = ['SONY XPERIA', 'SAMSUNG GALAXY', 'IPHONE']
|
||||
_tv = "TV"
|
||||
_grid_view = "//strong[@title='Grid']"
|
||||
_list_view = "List"
|
||||
_value = "//span[@id='product-price-1']/child::span"
|
||||
_add_to_cart = "//a[@title='Xperia']//following-sibling::div//span[text()='Add to Cart']"
|
||||
_cart_quantity = "//input[@data-cart-item-id='MOB001' and @title='Qty']"
|
||||
_update = "//button[@title='Update']/span/span"
|
||||
_error = "//span[text()='Some of the products cannot be ordered in requested quantity.']"
|
||||
_compare_xperia = "//a[@title='Xperia']//following-sibling::div/child::div/child::div/child::ul/li/a[text()='Add to Compare']"
|
||||
_compare_apple = "//a[@title='IPhone']//following-sibling::div/child::div/child::div/child::ul/li/a[text()='Add to Compare']"
|
||||
_compare_button = "//span[text()='Compare']"
|
||||
_iphone_new = "//a[text()='IPhone']"
|
||||
_close_window = "//span[text()='Close Window']"
|
||||
_available_mobile = "//div[@class='category-products']/ul/li/a"
|
||||
_mobile_text = "//li[@class='item last']//child::div/h2/a"
|
||||
_sort_by = "//select[@title='Sort By']"
|
||||
|
||||
|
||||
def mobile_tab(self):
|
||||
self.elementClick(self._mobile,"link")
|
||||
|
||||
def available_mobiles(self,expected_list):
|
||||
result = self.getAttributelist(self._available_mobile,'xpath','title')
|
||||
return self.utill.listcompare(result,expected_list)
|
||||
|
||||
def sort_by(self,visibleText):
|
||||
self.get_element_dropdown_value(self._sort_by,'xpath',selectType='text',value=visibleText)
|
||||
|
||||
def get_mobile_text(self):
|
||||
return self.getTextElementList(self._mobile_text,'xpath')
|
||||
|
||||
def verify_sort_functionality(self,result):
|
||||
result1 = self.get_mobile_text()
|
||||
res = result.strip('][').split(', ')
|
||||
print(res)
|
||||
return self.utill.listcompare(expectedList=res,actualList=result1)
|
||||
|
||||
def add_to_cart(self):
|
||||
self.elementClick(self._add_to_cart,'xpath')
|
||||
|
||||
def enter_cart_quantity_and_update(self):
|
||||
self.elementSend(self._cart_quantity,'xpath','1000')
|
||||
self.explicitwait(self._update,'xpath',20,0.1)
|
||||
self.elementClick(self._update,'xpath')
|
||||
return self.isElementDisplayed(self._error,'xpath')
|
||||
|
||||
|
||||
def click_tv_tab(self):
|
||||
self.elementClick(self._tv,'link')
|
||||
print('clicked on Tv')
|
||||
|
||||
|
||||
def click_list_view(self):
|
||||
self.elementClick(self._list_view,'link')
|
||||
|
||||
|
||||
def sony_price_grid_view(self):
|
||||
value1 = self.getText(self._value,'xpath')
|
||||
return value1
|
||||
|
||||
def sony_price_list_view(self):
|
||||
value2 = self.getText(self._value,'xpath')
|
||||
return value2
|
||||
|
||||
|
||||
|
||||
|
||||
def verify_price_different_view(self):
|
||||
self.click_list_view()
|
||||
return self.utill.verify_values(self.sony_price_list_view(),self.sony_price_grid_view())
|
||||
|
||||
def verify_max_cart_error(self):
|
||||
self.add_to_cart()
|
||||
return self.enter_cart_quantity_and_update()
|
||||
|
||||
def click_compare_(self):
|
||||
self.elementClick(self._compare_xperia,'xpath')
|
||||
self.elementClick(self._compare_apple,'xpath')
|
||||
self.elementClick(self._compare_button,'xpath')
|
||||
self.switching_to_window()
|
||||
result1 = self.isElementDisplayed(self._iphone_new,'xpath')
|
||||
self.elementClick(self._close_window,'xpath')
|
||||
return result1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
navigate to the test path
|
||||
|
||||
#run all pytest-bdd
|
||||
pytest -s -v --browser Chrome
|
||||
|
||||
#run only tags at Feature level
|
||||
pytest -s -v --browser Chrome -k "tagname"
|
||||
pytest -s -v --browser Chrome -k "tagname and tagname" #multiple tagnames. We can use any operator(and,or,not)
|
||||
|
||||
#run only tags at scenario/scenario's level
|
||||
pytest -s -v --browser Chrome -m "tagname"
|
After Width: | Height: | Size: 84 KiB |
After Width: | Height: | Size: 84 KiB |
After Width: | Height: | Size: 149 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 149 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 175 KiB |
After Width: | Height: | Size: 149 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 149 KiB |
After Width: | Height: | Size: 149 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 167 KiB |
After Width: | Height: | Size: 156 KiB |
After Width: | Height: | Size: 167 KiB |
After Width: | Height: | Size: 240 KiB |
After Width: | Height: | Size: 167 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 105 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 148 KiB |
After Width: | Height: | Size: 148 KiB |
|
@ -0,0 +1,63 @@
|
|||
import pytest
|
||||
from selenium import webdriver
|
||||
from pytest_bdd import given
|
||||
from pages.mobile_page.mobile_page import MobilePage
|
||||
from pages.account_creation.account_creation import Account
|
||||
from utilities.mark_test_status import MarkTestStatus
|
||||
|
||||
|
||||
|
||||
#hooks
|
||||
def pytest_bdd_step_error(request,feature,scenario,step,step_func,step_func_args,exception):
|
||||
print(f"step failed :: {step}")
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--browser")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def browser(request):
|
||||
return request.config.getoption("--browser")
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def setup(request, browser):
|
||||
if browser == 'Chrome':
|
||||
driver = webdriver.Chrome()
|
||||
|
||||
elif browser == 'ff':
|
||||
driver = webdriver.Firefox()
|
||||
|
||||
else:
|
||||
driver = webdriver.Chrome()
|
||||
|
||||
driver.maximize_window()
|
||||
driver.implicitly_wait(10)
|
||||
|
||||
if request.cls is not None:
|
||||
request.cls.driver = driver
|
||||
|
||||
yield driver
|
||||
driver.quit()
|
||||
|
||||
|
||||
@given("the ecommerce website is opened")
|
||||
def browser_initialization(setup):
|
||||
setup.get("http://live.demoguru99.com/index.php/")
|
||||
|
||||
|
||||
# -----POM Class initialization
|
||||
@pytest.fixture()
|
||||
def mobile(setup):
|
||||
return MobilePage(setup)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def account(setup):
|
||||
return Account(setup)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def mts(setup):
|
||||
return MarkTestStatus(setup)
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
@mobile #feature level tag
|
||||
Feature: ecommerce website
|
||||
As a buyer,
|
||||
I want to search mobile/TV online
|
||||
So I can buy mobile or TV
|
||||
|
||||
@sortBy #scenario level tag
|
||||
Scenario Outline: Check Sort By functionality
|
||||
Given the ecommerce website is opened
|
||||
When I click on Mobile Tab
|
||||
And I select Sort By "<Name>"
|
||||
Then all the available mobiles are sorted by "<result>"
|
||||
Examples:
|
||||
| Name | result |
|
||||
| Name | [IPHONE, SAMSUNG GALAXY, SONY XPERIA] |
|
||||
| Price | [SONY XPERIA, SAMSUNG GALAXY, IPHONE] |
|
||||
| Position | [SONY XPERIA, IPHONE, SAMSUNG GALAXY] |
|
||||
|
||||
|
||||
Scenario: Check Mobile Phone
|
||||
Given the ecommerce website is opened
|
||||
When I click on Mobile Tab
|
||||
Then all available mobiles are displayed
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
@registration
|
||||
Feature: ecommerce website
|
||||
As a buyer,
|
||||
I want to search mobile/TV online
|
||||
So I can buy mobile or TV
|
||||
|
||||
|
||||
Scenario Outline: Registration
|
||||
Given the ecommerce website is opened
|
||||
When I click on Account
|
||||
And I select Register option from dropdown menu
|
||||
And I enter "<firstname>" "<lastname>" "<email>" "<password>" "<confirm>"
|
||||
And I select the checkbox
|
||||
And I click the Register button
|
||||
Then I see the "<success>" message
|
||||
|
||||
Examples: Registration
|
||||
| firstname | lastname | email | password| confirm | success |
|
||||
| Test | twentynine |test@twentynine.com|test12345|test12345| Thank you for registering with Main Website Store.|
|
|
@ -0,0 +1,50 @@
|
|||
import pytest
|
||||
from pytest_bdd import scenario, given, when, then, parsers, scenarios
|
||||
from utilities.mark_test_status import MarkTestStatus
|
||||
|
||||
|
||||
@scenario("C:\\Users\\A610037\\PycharmProjects\\pytest-bdd\\tests\\features\\ecommerce.feature", "Check Mobile Phone")
|
||||
def test_one():
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@when("I click on Mobile Tab")
|
||||
def click_mobile_tab(mobile):
|
||||
mobile.mobile_tab()
|
||||
|
||||
|
||||
@then("all available mobiles are displayed")
|
||||
def mobile_phone_displayed(mobile, mts):
|
||||
result = mobile.available_mobiles(expected_list=['Xperia', 'IPhone', 'Samsung Galaxy'])
|
||||
mts.finalMark(testcase='Verify all mobiles are available', result=result,
|
||||
resultMessage='Verified all mobiles are available')
|
||||
|
||||
|
||||
extraTypes = {'value': str,
|
||||
'value2': list}
|
||||
convertors = {'name': str,
|
||||
'result': str
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@scenario("C:\\Users\\A610037\\PycharmProjects\\pytest-bdd\\tests\\features\\ecommerce.feature",
|
||||
scenario_name="Check Sort By functionality",example_converters= convertors)
|
||||
def test_sort_by_functionality():
|
||||
pass
|
||||
|
||||
|
||||
@when('I select Sort By "<Name>"')
|
||||
@when(parsers.cfparse("I select Sort By {Name:value}",extra_types=extraTypes))
|
||||
def when_click_sort_by_name(mobile,Name):
|
||||
mobile.sort_by(visibleText=Name)
|
||||
|
||||
|
||||
@then(parsers.cfparse("all the available mobiles are sorted by {result:value2}",extra_types=extraTypes))
|
||||
@then('all the available mobiles are sorted by "<result>"')
|
||||
def then_mobile_are_sorted(mobile,result,mts):
|
||||
result = mobile.verify_sort_functionality(result)
|
||||
mts.finalMark(testcase='Sort By',result=result,resultMessage='Sort By Functionality Tested')
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
from pytest_bdd import given,when,then,scenario,scenarios,parsers
|
||||
|
||||
|
||||
extraTypes = {'value': str}
|
||||
exampleConvertors = {'firstname': str,
|
||||
'lastname': str,
|
||||
'email': str,
|
||||
'password': str,
|
||||
'confirm': str,
|
||||
'name' : str,
|
||||
'result' : list
|
||||
}
|
||||
|
||||
|
||||
@scenario("C:\\Users\\A610037\\PycharmProjects\\pytest-bdd\\tests\\features\\registration.feature",'Registration',
|
||||
example_converters=exampleConvertors)
|
||||
|
||||
def test_registration():
|
||||
pass
|
||||
|
||||
|
||||
@when("I click on Account")
|
||||
@when("I select Register option from dropdown menu")
|
||||
def click_account(account):
|
||||
account.click_account()
|
||||
|
||||
|
||||
@when(parsers.cfparse(
|
||||
'I enter "{firstname:value}" "{lastname:value}" "{email:value}" "{password:value}""{confirm:value}"',
|
||||
extra_types=extraTypes))
|
||||
@when('I enter "<firstname>" "<lastname>" "<email>" "<password>" "<confirm>"')
|
||||
def provide_registration_data(account,firstname, lastname, email, password, confirm):
|
||||
account.fill_registration(firstname, lastname, email, password, confirm)
|
||||
|
||||
|
||||
@when("I select the checkbox")
|
||||
def select_checkbox(account):
|
||||
account.checkbox()
|
||||
|
||||
|
||||
@when("I click the Register button")
|
||||
def click_register_button(account):
|
||||
account.click_registration_button()
|
||||
|
||||
|
||||
@then(parsers.cfparse('I see the "{success:value}" message', extra_types=extraTypes))
|
||||
@then('I see the "<success>" message')
|
||||
def successful_registration(account, mts, success):
|
||||
result = account.success_message(success)
|
||||
mts.finalMark(testcase='Account Registration', result=result,
|
||||
resultMessage='Registration successful')
|
|
@ -0,0 +1,15 @@
|
|||
import csv
|
||||
|
||||
def getCsvData(fileName):
|
||||
rows = []
|
||||
|
||||
datafile = open(fileName, mode="r")
|
||||
|
||||
reader = csv.reader(datafile)
|
||||
|
||||
next(reader)
|
||||
|
||||
for row in reader:
|
||||
rows.append(row)
|
||||
|
||||
return rows
|
|
@ -0,0 +1,19 @@
|
|||
import logging
|
||||
import inspect
|
||||
|
||||
def custom_logger(loglevel = logging.INFO):
|
||||
loggername = inspect.stack()[1][3]
|
||||
|
||||
logger = logging.getLogger(loggername)
|
||||
logger.setLevel(loglevel)
|
||||
|
||||
filehander = logging.FileHandler(filename="Automation.log" , mode="a")
|
||||
filehander.setLevel(loglevel)
|
||||
|
||||
formatter = logging.Formatter('%(asctime)s: %(name)s: %(levelname)s: %(message)s', datefmt='%d:%m:%y %H:%M:%S')
|
||||
filehander.setFormatter(formatter)
|
||||
|
||||
|
||||
logger.addHandler(filehander)
|
||||
|
||||
return logger
|
|
@ -0,0 +1,15 @@
|
|||
import xlrd
|
||||
|
||||
def excel_data(sheetIndex,rowValues,filename):
|
||||
|
||||
wb = xlrd.open_workbook(filename)
|
||||
sheet = wb.sheet_by_index(sheetIndex)
|
||||
|
||||
data = sheet.row_values(rowValues)
|
||||
return data
|
||||
|
||||
|
||||
|
||||
atiqye = excel_data(0,0,filename="C:\\Users\\Atique\\PycharmProjects\\framework2\\datafiles\\test.xlsx")
|
||||
print(atiqye)
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
from utilities.customlogger import custom_logger
|
||||
import logging
|
||||
from base.selenium_driver import SeleniumDriver
|
||||
|
||||
|
||||
|
||||
class MarkTestStatus(SeleniumDriver):
|
||||
cl = custom_logger(logging.INFO)
|
||||
def __init__(self,driver):
|
||||
super(MarkTestStatus, self).__init__(driver)
|
||||
self.driver = driver
|
||||
|
||||
self.resultlist=[]
|
||||
|
||||
def setResult(self,result,resultMessage):
|
||||
try:
|
||||
if result is not None:
|
||||
if result is True:
|
||||
self.resultlist.append("Pass")
|
||||
self.cl.info("###Verification Successfull :: + " + resultMessage)
|
||||
else:
|
||||
self.resultlist.append("Fail")
|
||||
self.cl.info("###Verification Failed :: + " + resultMessage)
|
||||
self.savescreenshots(resultMessage)
|
||||
|
||||
else:
|
||||
self.resultlist.append("Fail")
|
||||
self.cl.info("###Verification Failed :: + " + resultMessage)
|
||||
|
||||
except:
|
||||
self.resultlist.append("Fail")
|
||||
self.savescreenshots(resultMessage)
|
||||
self.cl.info("### Exception Occured !!!")
|
||||
|
||||
|
||||
def mark(self,result,resultMessage):
|
||||
self.setResult(result,resultMessage)
|
||||
|
||||
|
||||
def finalMark(self,testcase,result,resultMessage):
|
||||
self.setResult(result, resultMessage)
|
||||
|
||||
if "Fail" in self.resultlist:
|
||||
self.cl.info(testcase + "### Test Failed")
|
||||
self.resultlist.clear()
|
||||
assert True == False
|
||||
|
||||
else:
|
||||
self.cl.info(testcase + "### Test Passed")
|
||||
self.resultlist.clear()
|
||||
assert True == True
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
from utilities.customlogger import custom_logger
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
import logging
|
||||
from traceback import print_stack
|
||||
|
||||
class Utilities():
|
||||
cl = custom_logger(logging.INFO)
|
||||
|
||||
def sleep(self,sec,info =""):
|
||||
if info is not None:
|
||||
self.cl.info("Wait :: " +str(sec) + " seconds for " + str(info) )
|
||||
try:
|
||||
time.sleep(sec)
|
||||
except InterruptedError:
|
||||
self.cl.error("Exception occured while Sleep")
|
||||
|
||||
|
||||
def verify_text_contains(self,actualText, expectedText):
|
||||
self.cl.info("Actual text from application URL is :: " + str(actualText))
|
||||
self.cl.info("Expected text from application URL is :: " + str(expectedText))
|
||||
|
||||
if actualText.lower() in expectedText.lower():
|
||||
self.cl.info("### Verfication Passed !!!")
|
||||
return True
|
||||
else:
|
||||
self.cl.info("### Verfication Failed !!!")
|
||||
return False
|
||||
|
||||
|
||||
def verify_text(self,actualText, expectedText):
|
||||
self.cl.info("Actual text from application URL is :: " + str(actualText))
|
||||
self.cl.info("Expected text from application URL is :: " + str(expectedText))
|
||||
|
||||
if actualText.lower() == expectedText.lower():
|
||||
self.cl.info("### Verfication Passed")
|
||||
return True
|
||||
else:
|
||||
self.cl.log.info("### Verfication Failed")
|
||||
return False
|
||||
|
||||
def getAlphaNumeric(self,length,type):
|
||||
|
||||
alpha_num = ""
|
||||
|
||||
if type == "lower":
|
||||
value = string.ascii_lowercase
|
||||
|
||||
elif type == "upper":
|
||||
value = string.ascii_uppercase
|
||||
|
||||
elif type == "digits":
|
||||
value = string.digits
|
||||
|
||||
elif type == "mix":
|
||||
value = string.ascii_letters + string.digits
|
||||
|
||||
elif type == "letters":
|
||||
value = string.ascii_letters
|
||||
|
||||
for i in range(0,length):
|
||||
return alpha_num.join(random.choice(value))
|
||||
|
||||
|
||||
def listcompare(self,expectedList, actualList):
|
||||
try:
|
||||
self.cl.info("Expected List is :: " + str(expectedList))
|
||||
self.cl.info("Actual List is :: " + str(actualList))
|
||||
|
||||
if len(expectedList) == len(actualList):
|
||||
i = 0
|
||||
for i in range(0, len(actualList)):
|
||||
if expectedList[i] == actualList[i]:
|
||||
i = i + 1
|
||||
if i == len(actualList):
|
||||
return True
|
||||
self.log.info("Both List Matched")
|
||||
|
||||
else:
|
||||
return False
|
||||
self.log.info("List Does not match")
|
||||
break
|
||||
else:
|
||||
print("List Length does not match")
|
||||
return False
|
||||
|
||||
except:
|
||||
print("List Length does not match")
|
||||
return False
|
||||
|
||||
|
||||
def verify_values(self,expectedValue,ActualValue):
|
||||
try:
|
||||
if expectedValue == ActualValue:
|
||||
self.cl.info("Matched")
|
||||
return True
|
||||
else:
|
||||
self.cl.info("Values dont match")
|
||||
return False
|
||||
except:
|
||||
self.cl.info("Exception occured.. Values dont match")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|