class WebdriverFactory():
    log = cl.customLogger(logging.DEBUG)

    def __init__(self,browser):
        self.chrome_api_location = "C:\\Users\\shekar\\PycharmProjects\\AutomationFW_Aug\\browserapis\\chromedriver.exe"
        os.environ["webdriver.chrome.driver"] = self.chrome_api_location
        self.ff_api_location = "C:\\Users\\shekar\\PycharmProjects\\AutomationFW_Aug\\browserapis\\geckodriver.exe"
        os.environ["webdriver.gecko.driver"] = self.ff_api_location
        self.ie_api_location = "C:\\Users\\shekar\\PycharmProjects\\AutomationFW_Aug\\browserapis\\IEDriverServer.exe"
        os.environ["webdriver.ie.driver"] = self.ie_api_location
        self.appurl = "http://localhost/login.do"
        self.browser = browser


    def getWebdriverInstance(self):
        if self.browser == "chrome":
            self.driver = webdriver.Chrome(executable_path=self.chrome_api_location)
            self.log.info("Execution will start in chrome browser")
        elif self.browser == "firefox":
            self.driver = webdriver.Firefox(executable_path=self.ff_api_location)
            self.log.info("Execution will start in firefox browser")
        elif self.browser == "ie":
            self.driver = webdriver.Ie(executable_path=self.ie_api_location)
            self.log.info("Execution will start in ie browser")
        else:
            self.log.error("Please provide the valid browser name")
            return False

        self.driver.get(self.appurl)
        self.log.info("Enter url "+self.appurl)
        self.driver.maximize_window()
        self.driver.implicitly_wait(50)
        return self.driver
Ejemplo n.º 2
0
class LoginPO(seleniumDriver):
    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    _userNameTxtBx = "//input[@name='username']"
    _pwdTxtBx = "//input[@name='pwd']"
    _login_Btn = "//div[contains(text(),'Login')]"
    _error_msg_txt = "//span[@class='errormsg']"

    def sendUsername(self, username="******"):
        self.send(self._userNameTxtBx, username, locatortype="xpath")
        self.log.info("Entered user name " + username)

    def sendpwd(self, pwd="manager"):
        self.send(self._pwdTxtBx, pwd, locatortype="xpath")
        self.log.info("Entered password " + pwd)

    def clickLoginBtn(self):
        self.click(self._login_Btn, locatortype="xpath")
        self.log.info("Clicked on login btn")

    def invalid_errormsg(self):
        self.hardwait(5)
        errormsg = self.getText(self._error_msg_txt, locatortype="xpath")
        print("Got error msg = " + errormsg)
        if "Username or Password is invalid. Please try again. fghf" == errormsg:
            return True
        else:
            return False
Ejemplo n.º 3
0
class Test_Case2(unittest.TestCase):
    log = cl.customLogger(logging.DEBUG)
    @pytest.fixture(autouse=True)
    def classSetup(self):
        print("Class level setup")
        self.lp = LoginPO(self.driver)

    def test_invalidlogin(self):
        self.lp.sendUsername("admin1")
        self.lp.sendpwd("pwd1")
        self.lp.clickLoginBtn()
        assert self.lp.invalid_errormsg() == True
        self.log.info("Validated the error message successfully")
Ejemplo n.º 4
0
class HomePO(seleniumDriver):
    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    _logoutBtn = "//a[contains(text(),'Logout')]"

    def clickLogoutBtn(self):
        self.hardwait(15)
        self.click(self._logoutBtn, locatortype="xpath")
        self.log.info("Clicked on logout btn")
Ejemplo n.º 5
0
class Test_Case3(unittest.TestCase):
    log = cl.customLogger(logging.DEBUG)
    @pytest.fixture(autouse=True)
    def classSetup(self):
        print("Class level setup")
        self.lp = LoginPO(self.driver)

    @data(*getcsvdata("C:\\Users\\shekar\\PycharmProjects\\"
                      "AutomationFW_Aug\\testdata.csv"))
    @unpack
    def test_invalidlogin(self,userName,Password):
        try:
            self.lp.sendUsername(userName)
            self.lp.sendpwd(Password)
            self.lp.clickLoginBtn()
            assert self.lp.invalid_errormsg() == True
            self.log.info("Validated the error message successfully")
        except:
            self.driver.get_screenshot_as_file("C:\\Users\\shekar\\PycharmProjects\\AutomationFW_Aug\\Screenshots\\test_invalidlogin.png")
Ejemplo n.º 6
0
class SeleniumDriver():

    log = CL.customLogger(logging.DEBUG)

    def __init__(self, driver):
        self.driver = driver

    def getByType(self, locatorType):
        locatorType = locatorType.lower()
        if locatorType == "id":
            return By.ID
        elif locatorType == "name":
            return By.NAME
        elif locatorType == "xpath":
            return By.XPATH
        elif locatorType == "css":
            return By.CSS_SELECTOR
        elif locatorType == "class":
            return By.CLASS_NAME
        elif locatorType == "link":
            return By.LINK_TEXT
        else:
            print("Locator type " + locatorType + " not correct/supported")
        return False

    def getElement(self, locator, locatorType="id"):
        element = None
        try:
            locatorType = locatorType.lower()
            bytype = self.getByType(locatorType)
            element = self.driver.find_element(bytype, locator)
            self.log.info("Element Found")
        except:
            self.log.info("Element not found")

        return element

    def elementClick(self, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            element.click()
            self.log.info("Clicked on element with locator: " + locator +
                          " locatorType: " + locatorType)
        except:
            self.log.info("Cannot click on the element with locator: " +
                          locator + " locatorType: " + locatorType)
            print_stack()

    def sendKeys(self, data, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            element.send_keys(data)
            self.log.info("Sent data on element with locator: " + locator +
                          " locatorType: " + locatorType)
        except:
            self.log.info("Cannot send data on the element with locator: " +
                          locator + " locatorType: " + locatorType)
            print_stack()

    def isElementPresent(self, locator, locatorType="id"):
        try:
            element = self.getElement(locator, locatorType)
            if element is not None:
                self.log.info("Element Found")
                return True
            else:
                self.log.info("Element not found")
                return False
        except:
            print("Element not found")
            return False

    def elementPresenceCheck(self, locator, byType):
        try:
            elementList = self.driver.find_elements(byType, locator)
            if len(elementList) > 0:
                self.log.info("Element Found")
                return True
            else:
                self.log.info("Element not found")
                return False
        except:
            print("Element not found")
            return False

    def waitForElement(self,
                       locator,
                       locatorType="id",
                       timeout=10,
                       pollFrequency=0.5):
        element = None
        try:
            byType = self.getByType(locatorType)
            self.log.info("Waiting for maximum :: " + str(timeout) +
                          " :: seconds for element to be clickable")
            wait = WebDriverWait(self.driver,
                                 timeout,
                                 poll_frequency=pollFrequency,
                                 ignored_exceptions=[
                                     NoSuchElementException,
                                     ElementNotVisibleException,
                                     ElementNotSelectableException
                                 ])
            element = wait.until(EC.element_to_be_clickable((byType, locator)))
            self.log.info("Element appeared on the web page")
        except:
            self.log.info("Element not appeared on the web page")
            print_stack()
        return element
Ejemplo n.º 7
0
class seleniumDriver():

    log = cl.customLogger(logging.DEBUG)

    def __init__(self, driver):
        self.driver = driver

    def getByType(self, locatortype="id"):
        locatortype = locatortype.lower()
        if locatortype == "css":
            return By.CSS_SELECTOR
        elif locatortype == "xpath":
            return By.XPATH
        elif locatortype == "id":
            return By.ID
        elif locatortype == "name":
            return By.NAME
        elif locatortype == "classname":
            return By.CLASS_NAME
        elif locatortype == "link":
            return By.LINK_TEXT
        elif locatortype == "partiallink":
            return By.PARTIAL_LINK_TEXT
        else:
            self.log.error("Please provide the valid locator")
            return False

    def getElement(self, locatorvalue, locatortype="id"):
        element = None
        try:
            bytype = self.getByType(locatortype)
            element = self.driver.find_element(bytype, locatorvalue)
            self.log.info("Identified element with locator " + locatortype +
                          "Locator value " + locatorvalue)
        except Exception as e:
            self.log.error("Element is not identified " + e)
        return element

    def getElements(self, locatorvalue, locatortype="id"):
        listofelements = None
        try:
            bytype = self.getByType(locatortype)
            listofelements = self.driver.find_elements(bytype, locatorvalue)
            self.log.info("Identified elements with locator " + locatortype +
                          "Locator value " + locatorvalue)
        except Exception as e:
            self.log.error("Elements is not identified " + e)
        return listofelements

    def isElementPresent(self, locatorvalue, locatortype="id"):
        element = self.getElement(locatortype, locatorvalue)
        if element is not None:
            self.log.info("Element is present")
            return True
        else:
            self.log.error("Element is not present")
            return False

    def click(self, locatorvalue, locatortype="id"):
        try:
            element = self.getElement(locatorvalue, locatortype)
            element.click()
            self.log.info("Clicked on Element with locator " + locatortype +
                          "locator value " + locatorvalue)
        except Exception as e:
            self.log.error("Unable to Click on Element with locator " +
                           locatortype + "locator value " + locatorvalue)

    def send(self, locatorvalue, value, locatortype="id"):
        try:
            element = self.getElement(locatorvalue, locatortype)
            element.send_keys(value)
            self.log.info("Sent data on Element with locator " + locatortype +
                          "locator value " + locatorvalue + " value " + value)
        except Exception as e:
            self.log.error("Unable to Send data on Element with locator " +
                           locatortype + "locator value " + locatorvalue +
                           " value " + value)

    def maximizewindow(self):
        self.driver.maximize_window()

    def minimizewindow(self):
        self.driver.minimize_window()

    def setbrowseractions(self, action="back"):
        if action == "back":
            self.driver.back()
        elif action == "forward":
            self.driver.forward()
        elif action == "refresh":
            self.driver.refresh()

    def getTitle(self):
        currenttitle = self.driver.title
        return currenttitle

    def getText(self, locatorvalue, locatortype="id"):
        element = self.getElement(locatorvalue, locatortype)
        return element.text

    def getPageSource(self):
        pagesource = self.driver.page_source
        return pagesource

    def hardwait(self, timesec=50):
        time.sleep(timesec)

    def closewindow(self):
        self.driver.close()

    def selectoptionfromdrpdwn(self,
                               locatorvalue,
                               visbletext="India",
                               locatortype="id"):
        try:
            element = self.getElement(locatorvalue, locatortype)
            sel = Select(element)
            sel.select_by_visible_text(visbletext)
            self.log.info("Selected option " + visbletext + " in drp dwn")
        except Exception as e:
            self.log.error("Unble to Select option " + visbletext +
                           " in drp dwn" + e)

    def deselectoptionfromdrpdwn(self,
                                 locatorvalue,
                                 visbletext="India",
                                 locatortype="id"):
        try:
            element = self.getElement(locatorvalue, locatortype)
            sel = Select(element)
            sel.deselect_by_visible_text(visbletext)
            self.log.info("DeSelected option " + visbletext + " in drp dwn")
        except Exception as e:
            self.log.error("Unble to DeSelect option " + visbletext +
                           " in drp dwn" + e)

    def handleFrame(self, locatorvalue, locatortype="id"):
        try:
            element = self.getElement(locatorvalue, locatortype)
            self.driver.switch_to.frame(element)
            self.log.info("Switched to iframe")
        except Exception as e:
            self.log.error("Unble to switch ti iframe" + e)

    def switchToParentFrame(self):
        self.driver.switch_to.parent_frame()

    def mouseover(self, locatorvalue, locatortype="id"):
        try:
            action = ActionChains(self.driver)
            element = self.getElement(locatorvalue, locatortype)
            action.move_to_element(element).perform()
            self.log.info("Successfull mouse over on element" + locatortype +
                          " " + locatorvalue)
        except Exception as e:
            self.log.error("UnSuccessfull mouse over on element" +
                           locatortype + " " + locatorvalue)

    def scrollPage(self, startindex=0, endindex=1000):
        self.driver.execute_script("window.scrollBy(" + startindex + "," +
                                   endindex + ");")

    def mouseclickAndHold(self, locatorvalue, locatortype="id"):
        try:
            action = ActionChains(self.driver)
            element = self.getElement(locatorvalue, locatortype)
            action.click_and_hold(element).perform()
            self.log.info("Successfull mouse click and hold on element" +
                          locatortype + " " + locatorvalue)
        except Exception as e:
            self.log.error("UnSuccessfull mouse click and hold on element" +
                           locatortype + " " + locatorvalue + " " + e)

    def getParentwindowid(self):
        parentwindowid = self.driver.current_window_handle
        return parentwindowid

    def getAllWindowids(self):
        listofwindowids = self.driver.window_handles
        return listofwindowids

    def switchToWindow(self, windowid=""):
        self.driver.switch_to.window(windowid)

    def switchToAlert(self, value="accept"):
        try:
            if value == "accept":
                self.driver.switch_to.alert.accept()
                self.log.info("Accepted the alert button")
            elif value == "dismiss":
                self.driver.switch_to.alert.dismiss()
                self.log.error("Dismissed the alert button")
        except Exception as e:
            self.log.error("Unable to switch to alert" + e)

    def webdriverwait_elementclickable(self,
                                       locatorvalue,
                                       time=10,
                                       pollfrequency=2,
                                       locatortype="id"):
        try:
            wait = WebDriverWait(self.driver,
                                 time,
                                 poll_frequency=pollfrequency,
                                 ignored_exceptions=[
                                     NoSuchElementException,
                                     ElementNotVisibleException
                                 ])
            element = self.getElement(locatorvalue, locatortype)
            wait.until(EC.element_to_be_clickable(element))
            self.log.info("Successfully waited for element with time " + time)
        except Exception as e:
            self.log.error("unSuccessfully in waiting for element with time " +
                           time + e)