Beispiel #1
0
    def __init__(self, obj_type, params, logger):
        """
        :param str obj_type:
        :param Objects.Params  params:
        :param CustomLogger logger:
        :rtype: None
        """
        self._type = obj_type
        self._params = params
        self._logger = CustomLogger(logger, names=[
            self._type.lower(),
        ])
        self.path = self._params.path

        self.ignored_regions = None
        self.data = None
        self.count = 0
        self.orig_n_frames = 0
        self.start_frame_id = 0
        self.end_frame_id = 0
        self.n_frames = 0
        self.idx = None
        # iou and index of the max iuo detection with each annotation or
        # the max iuo annotation with each detection in each frame
        self.max_cross_iou = None
        self.max_cross_iou_idx = None
        # future extensions
        self.features = None

        self._resize_factor = 1
Beispiel #2
0
 def test_loginFailMethod(self):
     cl.allureLogs("App Opened")
     self.gt.clickLoginBotton()
     self.gt.enterEmail()
     self.gt.enterPassword2()
     self.gt.clickOnLoginB()
     self.gt.verifyAdminScreen()
def getDriver():
    log = cl.customLogger(logging.DEBUG)
    log.info("=" * 20)
    log.info("Get Driver")
    driver = FromBrowser.getFromChrome(FromBrowser)
    yield driver
    driver.close()
def getLogin(getDriver):
    log = cl.customLogger(logging.DEBUG)
    log.info("=" * 20)
    log.info("Get Login")
    loginobj = LoginOperation(getDriver)
    loginobj.login(gcd.getUserName(gcd), gcd.getPassword(gcd))
    yield getDriver
class NavigationPage(BasePage):

    log = cl.CustomLogger(logging.DEBUG)

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

    #locators for https://letskodeit.teachable.com/
    _icon = "//a[@class='navbar-brand header-logo']"
    _practice_page = "Practice"
    _login_page = "//a[@class='navbar-link fedora-navbar-link']"
    _my_courses = "My Courses"
    _all_courses = "All Courses"
    _icon_profile = "//a[@class='fedora-navbar-link navbar-link dropdown-toggle open-my-profile-dropdown']"

    def navigationToIcon(self):
        self.clickElement(self._icon)

    def navigationToPracticePage(self):
        self.clickElement(self._practice_page, locatorType="link")

    def navigationToLoginPage(self):
        self.clickElement(self._login_page)

    def navigationToMyCourses(self):
        self.clickElement(self._my_courses, locatorType="link")

    def navigationToAllCourses(self):
        self.clickElement(self._all_courses, locatorType="link")

    def navigationToIconProfile(self):
        self.clickElement(self._icon_profile)
def getSurvey(getDriver):
    log = cl.customLogger(logging.DEBUG)
    log.info("=" * 20)
    log.info("Get Survey")
    loginobj = LoginOperation(getDriver)
    loginobj.login(gcd.getUserName(gcd), gcd.getPassword(gcd))
    cs = CreateSurvey(getDriver)
    cs.createSurvey()
    yield getDriver
class LoginPage(BasePage):

    log = cl.CustomLogger(logging.DEBUG)

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

    #locators
    _login_link = "//a[@class='navbar-link fedora-navbar-link']"
    _email_field = "//*[@id='user_email']"
    _password_field = "//*[@id='user_password']"
    _login_button = "//*[@name='commit']"

    def clickLoginLink(self):
        self.clickElement(self._login_link)

    def enterEmail(self, email):
        self.sendKeys(email, self._email_field)

    def enterPassword(self, password):
        self.sendKeys(password, self._password_field)

    def clickLogin(self):
        self.clickElement(self._login_button)

    def logging(self, email="", password=""):
        self.clickLoginLink()
        self.enterEmail(email)
        self.enterPassword(password)
        self.clickLogin()

    def clearing(self):
        self.clearField(self._email_field)
        self.clearField(self._password_field)

    def verifyLogin(self):
        verifier = self.isElementPresent("//img[@class='gravatar']")
        return verifier

    def verifyLoginFailed(self):
        verifier = self.isElementPresent(
            "//div[contains(text(), 'Invalid email or password.')]")
        return verifier

    def verifyLoginTitle(self):
        #return self.verifyPageTitle("Google")
        return self.verifyPageTitle("Let's Kode It")

    def logout(self):
        self.nav.navigationToIconProfile()
        self.clickElement("//a[@href='/sign_out']")
class Util(object):
    log = cl.CustomLogger(logging.INFO)

    def sleep(self, sec, info=""):
        if info is not None:
            self.log.info("Wait: " + str(sec) + " seconds for " + info)
        try:
            time.sleep(sec)
        except InterruptedError:
            traceback.print_stack()

    def getAlphaNumeric(self, length, type="letters"):
        alpha_num = ''
        if type == 'lower':
            case = string.ascii_lowercase
        elif type == 'upper':
            case = string.ascii_uppercase
Beispiel #9
0
class Status(SeleniumDriver):

    log = cl.CustomLogger(logging.INFO)

    def __init__(self, driver):
        super(Status, self).__init__(driver)
        self.resultList = []

    def setResult(self, result, resultMessage):
        try:
            if result is not None:
                if result:
                    self.resultList.append("PASS")
                    self.log.info("### VERIFICATION SUCCESSFUL : " +
                                  resultMessage)
                else:
                    self.resultList.append("FAIL")
                    self.log.error("### VERIFICATION FAILED : " +
                                   resultMessage)
                    self.screenShot(resultMessage)
            else:
                self.resultList.append("FAIL")
                self.log.error("### VERIFICATION FAILED : " + resultMessage)
                self.screenShot(resultMessage)
        except:
            self.resultList.append("FAIL")
            self.log.error("### EXCEPTION OCCURED")
            self.screenShot(resultMessage)
            print_stack()

    def mark(self, result, resultMessage):
        self.setResult(result, resultMessage)

    def markFinal(self, testName, result, resultMessage):
        self.setResult(result, resultMessage)
        if "FAIL" in self.resultList:
            self.log.error("### " + testName + " FAILED.")
            self.resultList.clear()
            assert True == False
        else:
            self.log.info("### " + testName + " SUCCESSFUL.")
            self.resultList.clear()
            assert True == True
 def verifyContactPage(self):
     element = self.isDisplayed(self._pagetitle, "text")
     assert element == True
     cl.allureLogs("Contact Us Form page opened")
Beispiel #11
0
class cHomepage(cSeleniumDriver):
    log = cl.CustomLogger(logging.DEBUG)
    #locators
    sSearchIn = "searchDropdownBox"
    sBooks = "//select[@id='searchDropdownBox']/option[text()='Books']"
    sSearchTextBox = "twotabsearchtextbox"
    sSearchIcon = "//input[@value='Go']"
    sFirstResult = "//li[@id='result_0']//img"
    sNoResult = "noResultsTitle"
    sSubNavBar = "//div[@id='nav-subnav']/a[1]/span"
    sSelectedDepartment = ".//select[@id='searchDropdownBox']/option[@selected='selected']"

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

    def ClickSearchDropDown(self):
        self.ElementClick(self.sSearchIn)

    def ClickBooksFromDropDown(self):
        self.ElementClick(self.sBooks,"xpath")

    def GetSearchBox(self):
        return  self.GetElement(self.sSearchTextBox)

    def EnterSearchKey(self, sSearchKey):
        self.SendKeys(sSearchKey, self.sSearchTextBox)

    def ClickSearchIcon(self):
        self.ElementClick(self.sSearchIcon, "xpath")

    def ClickFirstResult(self):
        self.ElementClick(self.sFirstResult, "xpath")

    def GetNoResultsText(self):
        return self.GetText(self.sNoResult)

    def GetTitle(self):
        time.sleep(2)
        return self.driver.title

    def GetSubNavBarPresence(self):
        return self.IsElementPresent(self.sSubNavBar, "xpath")

    def GetSelectedDepartmentText(self):
        return self.GetText(self.sSelectedDepartment, "xpath")

    def SearchBook(self, sSearchKey):
        self.ClickSearchDropDown()
        self.ClickBooksFromDropDown()
        self.EnterSearchKey(sSearchKey)
        time.sleep(2)
        self.ClickSearchIcon()

    def SelectBook(self):
        self.ClickFirstResult()

    def VerifyNoResultText(self, sSearchKey):
        self.SearchBook(sSearchKey)
        bResult = self.IsElementDisplayed(self.sNoResult)
        sSearchResultText = self.GetNoResultsText()
        return bResult, sSearchResultText

    def ClearSearchBar(self):
        self.GetSearchBox().clear()

    def VerifySubNavigationBarPresence(self):
        return self.GetSubNavBarPresence()
 def objectSetup(self, getDriver):
     log = cl.customLogger(logging.DEBUG)
     log.info("=" * 20)
     log.info("Login Operation")
     self.lo = LoginOperation(getDriver)
class SeleniumDriver():
    log = cl.CustomLogger(logging.DEBUG)

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

    def screenShot(self, resultMessage):
        fileName = resultMessage + "." + str(round(
            time.time() * 1000)) + ".png"
        screenShootDir = "../screenshots/"
        relativeFileName = screenShootDir + fileName
        currentDirectory = os.path.dirname(__file__)
        destinationFile = os.path.join(currentDirectory, relativeFileName)
        destinationDirectory = os.path.join(currentDirectory, screenShootDir)

        try:
            if not os.path.exists(destinationDirectory):
                os.makedirs(destinationDirectory)
            self.driver.save_screenshot(destinationFile)
            self.log.info("Screenshot saved to directory: " + destinationFile)
        except:
            self.log.error("Exception occured when taking screenshot.")
            print_stack()

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

    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
        elif locatorType == "partial":
            return By.PARTIAL_LINK_TEXT
        else:
            self.log.info("Locator type " + locatorType +
                          " not correct/supported")
        return False

    def getElement(self, locator, locatorType="xpath"):
        element = None
        try:
            locatorType = locatorType.lower()
            byType = self.getByType(locatorType)
            element = self.driver.find_element(byType, locator)
            self.log.info("Element found with locator: " + locator +
                          " and locatorType: " + locatorType)
        except:
            self.log.info("Element not found with locator: " + locator +
                          " and locatorType: " + locatorType)
        return element

    def getElementList(self, locator, locatorType="xpath"):
        element = None
        try:
            locatorType = locatorType.lower()
            byType = self.getByType(locatorType)
            element = self.driver.find_elements(byType, locator)
            self.log.info("Element found with locator: " + locator +
                          " and locatorType: " + locatorType)
        except:
            self.log.info("Element not found with locator: " + locator +
                          " and locatorType: " + locatorType)
        return element

    def clickElement(self, locator, locatorType="xpath", element=None):
        try:
            if locator:
                element = self.getElement(locator, locatorType)
            element.click()
            self.log.info("Clicked on the element with locator: " + locator +
                          " and locatorType: " + locatorType)
        except:
            self.log.info("Can't click on the element with locator: " +
                          locator + " and locatorType: " + locatorType)
            print_stack()

    def sendKeys(self, data, locator, locatorType="xpath", element=None):
        try:
            if locator:
                element = self.getElement(locator, locatorType)
            element.send_keys(data)
            self.log.info("Send keys to the element with locator: " + locator +
                          " and locatorType: " + locatorType)
        except:
            self.log.info("Couldn't send keys to the element with locator: " +
                          locator + " and locatorType: " + locatorType)
            print_stack()

    def getText(self, locator="", locatorType="id", element=None, info=""):
        try:
            if locator:
                self.log.debug("In locator condition")
                element = self.getElement(locator, locatorType)
            self.log.debug("Before finding text")
            text = element.text
            self.log.debug("After finding element, size is: " + str(len(text)))
            if len(text) == 0:
                text = element.get_attribute("innerText")
            if len(text) != 0:
                self.log.info("Getting text on element: " + info)
                self.log.info("The text is: '" + text + "'")
                text = text.strip()
        except:
            self.log.error("Failed to get text on element " + info)
            print_stack()
            text = None
        return text

    def clearField(self, locator, locatorType="xpath"):
        try:
            element = self.getElement(locator, locatorType)
            element.clear()
            self.log.info("Cleared element with locator: " + locator +
                          " and locatorType: " + locatorType)
        except:
            self.log.info("Couldn't clear element with locator: " + locator +
                          " and locatorType: " + locatorType)
            print_stack()

    def isElementPresent(self, locator, locatorType="xpath", element=None):
        try:
            if locator:
                element = self.getElement(locator, locatorType)
            if element is not None:
                self.log.info("Element present with locator: " + locator +
                              " and locatorType: " + locatorType)
                return True
            else:
                self.log.info("Element NOT present with locator: " + locator +
                              " and locatorType: " + locatorType)
                return False
        except:
            self.log.info("Element not found")
            return False

    def isElementDisplayed(self, locator="", locatorType="id", element=None):
        isDisplayed = False
        try:
            if locator:
                element = self.getElement(locator, locatorType)
            if element is not None:
                isDisplayed = element.is_displayed()
                self.log.info("Element is displayed with locator: " + locator +
                              " and locatorType: " + locatorType)
            return isDisplayed
        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")
        except:
            self.log.info("Element not found")
            return False

    def waitForElement(self,
                       locator,
                       locatorType="xpath",
                       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=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

    def webScroll(self, direction):
        if direction == "up":
            self.driver.execute_script("window.scrollBy(0, -1000);")
        elif direction == "down":
            self.driver.execute_script("window.scrollBy(0, 1000);")
        else:
            dir = self.driver.find_element(By.XPATH, direction)

            self.driver.execute_script("arguments[0].scrollIntoView();", dir)

    def switchToFrame(self, locator, locatorType="xpath", index=None):
        byType = self.getByType(locatorType)
        if index is not None:
            self.driver.switch_to.frame(index)
        elif byType == "xpath" or byType == "name":
            loc = self.getElement(locator, byType)
            self.driver.switch_to.frame(loc)
            self.log.info("Swapped to locator " + locator +
                          " with locatorType " + locatorType)
        else:
            self.log.info(locatorType + " is not supported for this operation")

    def SwitchFrameByIndex(self, locator, locatorType="xpath"):
        '''
        Get iframe index using element locator inside iframe given locatorType
        Returns: index inside iframe
        Exception: None
        '''
        result = False
        try:
            iframe_list = self.getElementList("//iframe", "xpath")
            self.log.info("Length of the iframe list is: ")
            self.log.info(str(len(iframe_list)))
            for i in range(len(iframe_list)):
                self.switchToFrameByIndex(index=iframe_list[i])
                result = self.isElementPresent(locator, locatorType)
                if result:
                    self.log.info("iframe index is ")
                    self.log.info(str(i))
                    break
                self.driver.switch_to.default_content()
            return result
        except:
            print("iframe index not found")
            return result
class BasePage:
    log = cl.customLogger()

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

    def waitForElement(self, locatorValue, locatorType):
        locatorType = locatorType.lower()
        element = None
        wait = WebDriverWait(self.driver, 25, poll_frequency=1,
                             ignored_exceptions=[ElementNotVisibleException,
                                                 ElementNotSelectableException,
                                                 NoSuchElementException])
        if locatorType =="id":
            element = wait.until(lambda x: x.find_element_by_id(locatorValue))
        elif locatorType == "class":
            element = wait.until(lambda x: x.find_element_by_class_name(locatorValue))
            return element
        elif locatorType == "des":
            element = wait.until(lambda x: x.find_element_by_android_uiautomator('UiSelector().description("%s")' % (locatorValue)))
            return element
        elif locatorType == "index":
            element = wait.until(lambda x: x.find_element_by_android_uiautomator("UiSelector().index(%d)" % int(locatorValue)))
            return element
        elif locatorType == "text":
            element = wait.until(lambda x: x.find_element_by_android_uiautomator('text("%s")' % locatorValue))
            return element
        elif locatorType == "xpath":
            element = wait.until(lambda x: x.find_element_by_xpath('%s' % (locatorValue)))
            return element
        else:
            self.log.info("Locator value " + locatorValue + "not found")

        return element

    def getElement(self, locatorValue, locatorType="id"):
        element = None
        try:
            locatorType = locatorType.lower()
            element = self.waitForElement(locatorValue, locatorType)
            self.log.info("Element found with LocatorType: " + locatorType + " with the locatorValue :" + locatorValue)
        except:
            self.log.info(
                "Element not found with LocatorType: " + locatorType + " and with the locatorValue :" + locatorValue)

        return element

    def clickElement(self, locatorValue, locatorType="id"):
        element = None
        try:
            locatorType = locatorType.lower()
            element = self.getElement(locatorValue, locatorType)
            element.click()
            self.log.info(
                "Clicked on Element with LocatorType: " + locatorType + " and with the locatorValue :" + locatorValue)
        except:
            self.log.info(
                "Unable to click on Element with LocatorType: " + locatorType + " and with the locatorValue :" + locatorValue)

    def sendText(self, text, locatorValue, locatorType="id"):
        element = None
        try:
            locatorType = locatorType.lower()
            element = self.getElement(locatorValue, locatorType)
            element.send_keys(text)
            self.log.info(
                "Send text  on Element with LocatorType: " + locatorType + " and with the locatorValue :" + locatorValue)
        except:
            self.log.info(
                "Unable to send text on Element with LocatorType: " + locatorType + " and with the locatorValue :" + locatorValue)
            self.takeScreenshot(locatorType)
            assert False
    def isDisplayed(self, locatorValue, locatorType="id"):
        element = None
        try:
            locatorType = locatorType.lower()
            element = self.getElement(locatorValue, locatorType)
            element.is_displayed()
            self.log.info(
                " Element with LocatorType: " + locatorType + " and with the locatorValue :" + locatorValue + "is displayed ")
            return True
        except:
            self.log.info(
                " Element with LocatorType: " + locatorType + " and with the locatorValue :" + locatorValue + " is not displayed")
            self.takeScreenshot(locatorType)
            return False

    def screenShot(self, screenshotName):
        fileName = screenshotName + "_" + (time.strftime("%d_%m_%y_%H_%M_%S")) + ".png"
        screenshotDirectory = "../screenshots/"
        screenshotPath = screenshotDirectory + fileName
        try:
            self.driver.save_screenshot(screenshotPath)
            self.log.info("Screenshot save to Path : " + screenshotPath)
        except:
            self.log.info("Unable to save Screenshot to the Path : " + screenshotPath)

    def takeScreenshot(self, text):
        allure.attach(self.driver.get_screenshot_as_png(), name=text, attachment_type=AttachmentType.PNG)

    def keyCode(self, value):
        self.driver.press_keycode(value)
Beispiel #15
0
class cBookSearch(unittest.TestCase):
    log = cl.CustomLogger(logging.DEBUG)

    @pytest.fixture(autouse=True)
    def ObjectSetup(self, OneTimeSetUp):
        self.oHomePage = cHomepage(self.driver)
        self.oBook = cProductBook(self.driver)
        self.oTS = cTestStatus(self.driver)
        self.bResult = True
        self.lFailureMsg = []

    @data(*GetCSVData(os.path.join(os.getcwd(),"testdata.csv")))
    @unpack
    #@pytest.mark.run(order=3)
    def test_3_VerifyBookSearch(self, sBookToSearch):
        try:
            self.PrintStep("3 : test_VerifyBookSearch")

            self.oHomePage.SearchBook(sBookToSearch)
            self.assertEqual("Books", self.oHomePage.GetSelectedDepartmentText())
            sTitle = self.oHomePage.GetTitle()
            self.assertEqual(sTitle, "Amazon.com: " + sBookToSearch + ": Books")
            bPresent = self.oHomePage.VerifySubNavigationBarPresence()
            if not bPresent:
                self.UpdateResult(False, "Sub Navigation Bar Verification")

            self.oHomePage.SelectBook()
            sTitle, dAuthorInfo = self.oBook.GetBookInfo()
            dBookPrice = self.oBook.GetBookPrice()
            sRatings = self.oBook.GetBookRatings()
            self.log.info("\n")
            self.log.info("------------------")
            self.log.info(" BOOK INFORMATION ")
            self.log.info("------------------")

            if sTitle != None:
                self.log.info("Book Title : " + str(sTitle))
            else:
                self.UpdateResult(False, "Unable to get Title")

            if len(dAuthorInfo) >= 1:
                for sAuthor in dAuthorInfo.keys():
                    self.log.info("By : " + str(sAuthor))
                    self.log.info("Contribution : " + str(dAuthorInfo[sAuthor]))
            else:
                self.UpdateResult(False, "Unable to get Author Info")

            if sRatings != None:
                self.log.info("Ratings : " + sRatings)
            else:
                self.UpdateResult(False, "Unable to get Ratings")

            if len(dBookPrice) >= 1:
                self.log.info("Available modes and price :")
                for sMode in dBookPrice.keys():
                    self.log.info(str(sMode) + " : " + str(dBookPrice[sMode]))
            else:
                self.UpdateResult(False, "Unable to get Book Price")

            if not self.bResult:
                self.oTS.FinalResult("test_3_VerifyBookSearch", self.bResult, str(self.lFailureMsg))
            else:
                self.oTS.FinalResult("test_3_VerifyBookSearch", self.bResult, "Book Information")

        except (KeyError, ValueError, TypeError) as Ex:
            self.log.error("Error Occured : " + str(Ex))
            self.oTS.FinalResult("test_3_VerifyBookSearch", False, "KeyError, ValueError, TypeError")
        except AssertionError as Ex:
            self.log.error("Assertion Error : " + str(Ex))
            self.oTS.FinalResult("test_3_VerifyBookSearch", False, "Assertion Fail")

    #@pytest.mark.run(order=2)
    def test_2_VerifyNoResults(self):
        try:
            self.PrintStep("2 : test_VerifyNoResults")

            sSearchKey = "Kurudhipunal"
            self.bResult, sSearchResulText = self.oHomePage.VerifyNoResultText(sSearchKey)
            self.assertEqual("Books", self.oHomePage.GetSelectedDepartmentText())
            sTitle = self.oHomePage.GetTitle()
            self.assertEqual(sTitle, "Amazon.com: " + sSearchKey + ": Books")
            if self.bResult:
                self.assertIn(sSearchKey, sSearchResulText)

            self.oTS.FinalResult("test_VerifyNoResults", self.bResult, "No Result Verification")

        except AssertionError as Ex:
            self.log.error("Assertion Error : " + str(Ex))
            self.oTS.FinalResult("test_NoResult", False, "Assertion Fail")


    # @pytest.mark.run(order=1)
    def test_1_VerifyTitle(self):
        try:
            self.PrintStep("1 : test_VerifyTitle")

            sTitle = self.oHomePage.GetTitle()
            self.assertEqual(sTitle, "Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more")
            self.oTS.FinalResult("test_VerifyTitle", self.bResult, "Title Verification")
        except AssertionError as Ex:
            self.log.error("Assertion Error : " + str(Ex))
            self.oTS.FinalResult("test_VerifyTitle", False, "Assertion Fail")

    def PrintStep(self, sTestName):
        self.log.info("******************************")
        self.log.info("Test " + sTestName)
        self.log.info("******************************")
        self.log.info("\n")

    def UpdateResult(self, bResult, sMsg):
        self.bResult = bResult
        self.lFailureMsg.append(sMsg)
        self.oTS.StepResult(self.bResult, sMsg)

    def tearDown(self):
        self.oHomePage.ClearSearchBar()
class SeleniumDriver():

    log = cl.Custom_Logger(logging.DEBUG)

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

    def getByType(self,locatortype):
        if locatortype == 'id':
            return By.ID
        elif locatortype == 'name':
            return By.NAME
        elif locatortype == 'xpath':
            return By.XPATH
        elif locatortype == 'class':
            return By.CLASS_NAME
        elif locatortype == "tag_name":
            return By.TAG_NAME
        elif locatortype == 'css_selector':
            return By.CSS_SELECTOR
        elif locatortype == 'link_text':
            return By.LINK_TEXT
        else:
            self.log.info("Not Supported locator")
        return False

    def getElement(self,locator,locatortype):
        try:
            byType = self.getByType(locatortype)
            element = self.driver.find_element(byType, locator)
            self.log.info("Element Found  " + locator +" and the locator type is " + locatortype)
            return element
        except:
            self.log.info("Element not found " + locator)

    def elementClick(self, locator, locatortype):
        element = self.getElement(locator,locatortype)
        element.click()

    def sendkeys(self, data, locator, locatortype):
        element = self.getElement(locator,locatortype)
        element.send_keys(data)

    def isElementPresent(self, locator, locatortype):
        element = self.getElement(locator,locatortype)
        if element is not None:
            self.log.info("Element is present in the screen " + locator)
            return True
        else:
            self.log.info("Element is not present in the screen " + locator)
            return False

    def clearfields(self, locator, locatortype):
        element = self.getElement(locator,locatortype)
        element.clear()

    def mousehover(self, locator1, locatortype1, locator2, locatortype2):
        element1 = self.getElement(locator1, locatortype1)
        element2 = self.getElement(locator2, locatortype2)
        action = ActionChains(self.driver)
        action.move_to_element(element1).move_to_element(element2).click().perform()
 def clickContactFormButton(self):
     self.clickElement(self._contactFromButton, "id")
     cl.allureLogs("Clicked on Contact us From Button")
Beispiel #18
0
    def initialize(self, seq_set_id, seq_id, seq_type_id, logger=None):
        """
        :type seq_set_id: int
        :type seq_id: int
        :type seq_type_id: int
        :type logger: CustomLogger
        :rtype: bool
        """

        if logger is not None:
            self.__logger = logger

        if seq_set_id < 0 or seq_id < 0:
            self._logger.info('Using external sequence')
            return

        self.seq_set = self.sets[seq_set_id]
        self.seq_name = self.sequences[self.seq_set][seq_id][0]
        self.seq_n_frames = self.sequences[self.seq_set][seq_id][1]

        self._logger = CustomLogger(self.__logger,
                                    names=(self.seq_name, ),
                                    key='custom_header')

        seq_ratios = self.ratios[self.seq_set][seq_id]

        start_offset = self.params.offsets[seq_type_id]

        if seq_type_id == 0:
            seq_type = 'training'
            seq_ratio = seq_ratios[0]
        else:
            seq_type = 'testing'
            if seq_ratios[1] == 0:
                """
                test on all non-training frames
                """
                if seq_ratios[0] < 0:
                    """training samples from end"""
                    seq_ratio = seq_ratios[0] + 1
                else:
                    seq_ratio = seq_ratios[0] - 1
            else:
                seq_ratio = seq_ratios[1]

        self.start_frame_id, self.end_frame_id = self.get_sub_seq_idx(
            seq_ratio, start_offset, self.seq_n_frames)

        if self.seq_n_frames <= self.start_frame_id or \
                self.start_frame_id < 0 or \
                self.seq_n_frames <= self.end_frame_id or \
                self.end_frame_id <= 0 or \
                self.end_frame_id < self.start_frame_id:
            self._logger.error(
                'Invalid {:s} ratio: {:.2f} or start frame id: {:d} '
                'specified'.format(seq_type, seq_ratio, start_offset,
                                   self.seq_n_frames))
            return False

        self._logger.info('seq_ratios: {}'.format(seq_ratios))
        self._logger.info('seq_ratio: {:f}'.format(seq_ratio))
        self._logger.info('start_offset: {:d}'.format(start_offset))
        self.is_initialized = True

        return True
Beispiel #19
0
class Data:
    """
    :type params: Data.Params
    """
    class Params:
        """
        :ivar ratios: 'two element tuple to indicate fraction of frames in each sequence on which'
                  ' (training, testing) is to be performed; '
                  'negative values mean that frames are taken from the end of the sequence; '
                  'zero for the second entry means that all frames not used for training are used for '
                  'testing in each sequence; '
                  'if either entry is > 1, it is set to the corresponding value for the sequence set being used',
        :ivar offsets: 'two element tuple to indicate offsets in the start frame ID with respect to the sub sequence'
                   ' obtained from the (train, test) ratios on which (training, testing) is to be performed;'
                   'ratios and offsets together specify the subsequences, if any, on which the two components'
                   ' of the program are to be run',
        :ivar ratios_gram: 'train and test ratios for sequences in the GRAM dataset',
        :ivar ratios_idot: 'train and test ratios for sequences in the IDOT dataset',
        :ivar ratios_detrac: 'train and test ratios for sequences in the DETRAC dataset',
        :ivar ratios_lost: 'train and test ratios for sequences in the LOST dataset',
        :ivar ratios_isl: 'train and test ratios for sequences in the ISL dataset',
        :ivar ratios_mot2015: 'train and test ratios for sequences in the MOT2015 dataset',
        :ivar ratios_kitti: 'train and test ratios for sequences in the KITTI dataset',

        """
        def __init__(self):
            self.ratios = [1., 1.]
            self.offsets = [0., 0.]

            self.ratios_gram = [1., 0.]
            self.ratios_idot = [1., 0.]
            self.ratios_detrac = [1., 0.]
            self.ratios_lost = [1., 0.]
            self.ratios_isl = [1., 1.]
            self.ratios_mot2015 = [1., 0.]
            self.ratios_mot2017 = [1., 0.]
            self.ratios_mot2017_sdp = [1., 0.]
            self.ratios_mot2017_dpm = [1., 0.]
            self.ratios_kitti = [1., 0.]
            self.ratios_mnist_mot = [1., 1.]

        def synchronize(self, _id=0):
            attrs = paramparse.get_valid_members(self)
            for attr in attrs:
                if attr == 'tee_log':
                    continue
                attr_val = list(getattr(self, attr))
                attr_val[1 - _id] = attr_val[_id]
                setattr(self, attr, attr_val)

    def __init__(self, params, logger):
        """
        :type params: Data.Params
        :type logger: logging.RootLogger | CustomLogger
        :rtype: None
        """
        self.params = params
        self._logger = logger
        self.__logger = logger

        self.sets, self.sequences, self.ratios = self.get_sequences()

        self.seq_set = None
        self.seq_name = None
        self.seq_n_frames = 0
        # self.seq_ratios = list(self.params.ratios)

        self.start_frame_id = 0
        self.end_frame_id = 0

        self.is_initialized = False

    def initialize(self, seq_set_id, seq_id, seq_type_id, logger=None):
        """
        :type seq_set_id: int
        :type seq_id: int
        :type seq_type_id: int
        :type logger: CustomLogger
        :rtype: bool
        """

        if logger is not None:
            self.__logger = logger

        if seq_set_id < 0 or seq_id < 0:
            self._logger.info('Using external sequence')
            return

        self.seq_set = self.sets[seq_set_id]
        self.seq_name = self.sequences[self.seq_set][seq_id][0]
        self.seq_n_frames = self.sequences[self.seq_set][seq_id][1]

        self._logger = CustomLogger(self.__logger,
                                    names=(self.seq_name, ),
                                    key='custom_header')

        seq_ratios = self.ratios[self.seq_set][seq_id]

        start_offset = self.params.offsets[seq_type_id]

        if seq_type_id == 0:
            seq_type = 'training'
            seq_ratio = seq_ratios[0]
        else:
            seq_type = 'testing'
            if seq_ratios[1] == 0:
                """
                test on all non-training frames
                """
                if seq_ratios[0] < 0:
                    """training samples from end"""
                    seq_ratio = seq_ratios[0] + 1
                else:
                    seq_ratio = seq_ratios[0] - 1
            else:
                seq_ratio = seq_ratios[1]

        self.start_frame_id, self.end_frame_id = self.get_sub_seq_idx(
            seq_ratio, start_offset, self.seq_n_frames)

        if self.seq_n_frames <= self.start_frame_id or \
                self.start_frame_id < 0 or \
                self.seq_n_frames <= self.end_frame_id or \
                self.end_frame_id <= 0 or \
                self.end_frame_id < self.start_frame_id:
            self._logger.error(
                'Invalid {:s} ratio: {:.2f} or start frame id: {:d} '
                'specified'.format(seq_type, seq_ratio, start_offset,
                                   self.seq_n_frames))
            return False

        self._logger.info('seq_ratios: {}'.format(seq_ratios))
        self._logger.info('seq_ratio: {:f}'.format(seq_ratio))
        self._logger.info('start_offset: {:d}'.format(start_offset))
        self.is_initialized = True

        return True

    def get_sub_seq_idx(self, seq_ratio, start_offset, n_frames):
        if seq_ratio < 0:
            """
            sample from end
            """
            start_idx = int(n_frames * (1 + seq_ratio)) - start_offset
            end_idx = int(round(n_frames - start_offset - 1))
        else:
            start_idx = int(start_offset)
            end_idx = int(round(n_frames * seq_ratio)) + start_offset - 1
        if start_idx < 0:
            start_idx = 0
        if end_idx >= n_frames:
            end_idx = n_frames - 1
        return start_idx, end_idx

    def get_inv_sub_seq_idx(self, sub_seq_ratio, start_offset, n_frames):
        if sub_seq_ratio < 0:
            inv_sub_seq_ratio = sub_seq_ratio + 1
        else:
            inv_sub_seq_ratio = sub_seq_ratio - 1
        return self.get_sub_seq_idx(inv_sub_seq_ratio, start_offset, n_frames)

    def combine_sequences(self, seq_lists):
        combined_sequences = {}
        offset = 0
        for sequences in seq_lists:
            for key in sequences:
                combined_sequences[key + offset] = sequences[key]
            offset += len(sequences)
        return combined_sequences

    def get_sequences(self):
        # names of sequences and the no. of frames in each
        sequences_mot2015 = {
            # train
            0: ('ADL-Rundle-6', 525),
            1: ('ADL-Rundle-8', 654),
            2: ('ETH-Bahnhof', 1000),
            3: ('ETH-Pedcross2', 837),
            4: ('ETH-Sunnyday', 354),
            5: ('KITTI-13', 340),
            6: ('KITTI-17', 145),
            7: ('PETS09-S2L1', 795),
            8: ('TUD-Campus', 71),
            9: ('TUD-Stadtmitte', 179),
            10: ('Venice-2', 600),
            # test
            11: ('ADL-Rundle-1', 500),
            12: ('ADL-Rundle-3', 625),
            13: ('AVG-TownCentre', 450),
            14: ('ETH-Crossing', 219),
            15: ('ETH-Jelmoli', 440),
            16: ('ETH-Linthescher', 1194),
            17: ('KITTI-16', 209),
            18: ('KITTI-19', 1059),
            19: ('PETS09-S2L2', 436),
            20: ('TUD-Crossing', 201),
            21: ('Venice-1', 450),
        }
        sequences_mot2017 = {
            # train
            0: ('MOT17-02-FRCNN', 600),
            1: ('MOT17-04-FRCNN', 1050),
            2: ('MOT17-05-FRCNN', 837),
            3: ('MOT17-09-FRCNN', 525),
            4: ('MOT17-10-FRCNN', 654),
            5: ('MOT17-11-FRCNN', 900),
            6: ('MOT17-13-FRCNN', 750),
            # test
            7: ('MOT17-01-FRCNN', 450),
            8: ('MOT17-03-FRCNN', 1500),
            9: ('MOT17-06-FRCNN', 1194),
            10: ('MOT17-07-FRCNN', 500),
            11: ('MOT17-08-FRCNN', 625),
            12: ('MOT17-12-FRCNN', 900),
            13: ('MOT17-14-FRCNN', 750),
        }
        sequences_mot2017_sdp = {
            # train
            0: ('MOT17-02-SDP', 600),
            1: ('MOT17-04-SDP', 1050),
            2: ('MOT17-05-SDP', 837),
            3: ('MOT17-09-SDP', 525),
            4: ('MOT17-10-SDP', 654),
            5: ('MOT17-11-SDP', 900),
            6: ('MOT17-13-SDP', 750),
            # test
            7: ('MOT17-01-SDP', 450),
            8: ('MOT17-03-SDP', 1500),
            9: ('MOT17-06-SDP', 1194),
            10: ('MOT17-07-SDP', 500),
            11: ('MOT17-08-SDP', 625),
            12: ('MOT17-12-SDP', 900),
            13: ('MOT17-14-SDP', 750),
        }

        sequences_mot2017_dpm = {
            # train
            0: ('MOT17-02-DPM', 600),
            1: ('MOT17-04-DPM', 1050),
            2: ('MOT17-05-DPM', 837),
            3: ('MOT17-09-DPM', 525),
            4: ('MOT17-10-DPM', 654),
            5: ('MOT17-11-DPM', 900),
            6: ('MOT17-13-DPM', 750),
            # test
            7: ('MOT17-01-DPM', 450),
            8: ('MOT17-03-DPM', 1500),
            9: ('MOT17-06-DPM', 1194),
            10: ('MOT17-07-DPM', 500),
            11: ('MOT17-08-DPM', 625),
            12: ('MOT17-12-DPM', 900),
            13: ('MOT17-14-DPM', 750),
        }

        sequences_kitti = {
            0: ('train_0000', 154),
            1: ('train_0001', 447),
            2: ('train_0002', 233),
            3: ('train_0003', 144),
            4: ('train_0004', 314),
            5: ('train_0005', 297),
            6: ('train_0006', 270),
            7: ('train_0007', 800),
            8: ('train_0008', 390),
            9: ('train_0009', 803),
            10: ('train_0010', 294),
            11: ('train_0011', 373),
            12: ('train_0012', 78),
            13: ('train_0013', 340),
            14: ('train_0014', 106),
            15: ('train_0015', 376),
            16: ('train_0016', 209),
            17: ('train_0017', 145),
            18: ('train_0018', 339),
            19: ('train_0019', 1059),
            20: ('train_0020', 837),
            21: ('test_0000', 465),
            22: ('test_0001', 147),
            23: ('test_0002', 243),
            24: ('test_0003', 257),
            25: ('test_0004', 421),
            26: ('test_0005', 809),
            27: ('test_0006', 114),
            28: ('test_0007', 215),
            29: ('test_0008', 165),
            30: ('test_0009', 349),
            31: ('test_0010', 1176),
            32: ('test_0011', 774),
            33: ('test_0012', 694),
            34: ('test_0013', 152),
            35: ('test_0014', 850),
            36: ('test_0015', 701),
            37: ('test_0016', 510),
            38: ('test_0017', 305),
            39: ('test_0018', 180),
            40: ('test_0019', 404),
            41: ('test_0020', 173),
            42: ('test_0021', 203),
            43: ('test_0022', 436),
            44: ('test_0023', 430),
            45: ('test_0024', 316),
            46: ('test_0025', 176),
            47: ('test_0026', 170),
            48: ('test_0027', 85),
            49: ('test_0028', 175)
        }
        sequences_gram = {
            0: ('M-30', 7520),
            1: ('M-30-HD', 9390),
            2: ('Urban1', 23435),
            # 3: ('M-30-Large', 7520),
            # 4: ('M-30-HD-Small', 9390)
        }
        sequences_idot = {
            0: ('idot_1_intersection_city_day', 8991),
            1: ('idot_2_intersection_suburbs', 8990),
            2: ('idot_3_highway', 8981),
            3: ('idot_4_intersection_city_day', 8866),
            4: ('idot_5_intersection_suburbs', 8851),
            5: ('idot_6_highway', 8791),
            6: ('idot_7_intersection_city_night', 8964),
            7: ('idot_8_intersection_city_night', 8962),
            8: ('idot_9_intersection_city_day', 8966),
            9: ('idot_10_city_road', 7500),
            10: ('idot_11_highway', 7500),
            11: ('idot_12_city_road', 7500),
            12: ('idot_13_intersection_city_day', 8851),
            # 13: ('idot_1_intersection_city_day_short', 84)
        }
        sequences_lost = {
            0: ('009_2011-03-23_07-00-00', 3027),
            1: ('009_2011-03-24_07-00-00', 5000)
        }
        sequences_isl = {
            0: ('isl_1_20170620-055940', 10162),
            1: ('isl_2_20170620-060941', 10191),
            2: ('isl_3_20170620-061942', 10081),
            3: ('isl_4_20170620-062943', 10089),
            4: ('isl_5_20170620-063943', 10177),
            5: ('isl_6_20170620-064944', 10195),
            6: ('isl_7_20170620-065944', 10167),
            7: ('isl_8_20170620-070945', 10183),
            8: ('isl_9_20170620-071946', 10174),
            9: ('isl_10_20170620-072946', 10127),
            10: ('isl_11_20170620-073947', 9738),
            11: ('isl_12_20170620-074947', 10087),
            12: ('isl_13_20170620-075949', 8614),
            13: ('ISL16F8J_TMC_SCU2DJ_2016-10-05_0700', 1188000),
            14: ('DJI_0020_masked_2000', 2000),
            15: ('debug_with_colors', 10)
        }
        sequences_detrac = {
            # train
            0: ('detrac_1_MVI_20011', 664),
            1: ('detrac_2_MVI_20012', 936),
            2: ('detrac_3_MVI_20032', 437),
            3: ('detrac_4_MVI_20033', 784),
            4: ('detrac_5_MVI_20034', 800),
            5: ('detrac_6_MVI_20035', 800),
            6: ('detrac_7_MVI_20051', 906),
            7: ('detrac_8_MVI_20052', 694),
            8: ('detrac_9_MVI_20061', 800),
            9: ('detrac_10_MVI_20062', 800),
            10: ('detrac_11_MVI_20063', 800),
            11: ('detrac_12_MVI_20064', 800),
            12: ('detrac_13_MVI_20065', 1200),
            13: ('detrac_14_MVI_39761', 1660),
            14: ('detrac_15_MVI_39771', 570),
            15: ('detrac_16_MVI_39781', 1865),
            16: ('detrac_17_MVI_39801', 885),
            17: ('detrac_18_MVI_39811', 1070),
            18: ('detrac_19_MVI_39821', 880),
            19: ('detrac_20_MVI_39851', 1420),
            20: ('detrac_21_MVI_39861', 745),
            21: ('detrac_22_MVI_39931', 1270),
            22: ('detrac_23_MVI_40131', 1645),
            23: ('detrac_24_MVI_40141', 1600),
            24: ('detrac_25_MVI_40152', 1750),
            25: ('detrac_26_MVI_40161', 1490),
            26: ('detrac_27_MVI_40162', 1765),
            27: ('detrac_28_MVI_40171', 1150),
            28: ('detrac_29_MVI_40172', 2635),
            29: ('detrac_30_MVI_40181', 1700),
            30: ('detrac_31_MVI_40191', 2495),
            31: ('detrac_32_MVI_40192', 2195),
            32: ('detrac_33_MVI_40201', 925),
            33: ('detrac_34_MVI_40204', 1225),
            34: ('detrac_35_MVI_40211', 1950),
            35: ('detrac_36_MVI_40212', 1690),
            36: ('detrac_37_MVI_40213', 1790),
            37: ('detrac_38_MVI_40241', 2320),
            38: ('detrac_39_MVI_40243', 1265),
            39: ('detrac_40_MVI_40244', 1345),
            40: ('detrac_41_MVI_40732', 2120),
            41: ('detrac_42_MVI_40751', 1145),
            42: ('detrac_43_MVI_40752', 2025),
            43: ('detrac_44_MVI_40871', 1720),
            44: ('detrac_45_MVI_40962', 1875),
            45: ('detrac_46_MVI_40963', 1820),
            46: ('detrac_47_MVI_40981', 1995),
            47: ('detrac_48_MVI_40991', 1820),
            48: ('detrac_49_MVI_40992', 2160),
            49: ('detrac_50_MVI_41063', 1505),
            50: ('detrac_51_MVI_41073', 1825),
            51: ('detrac_52_MVI_63521', 2055),
            52: ('detrac_53_MVI_63525', 985),
            53: ('detrac_54_MVI_63544', 1160),
            54: ('detrac_55_MVI_63552', 1150),
            55: ('detrac_56_MVI_63553', 1405),
            56: ('detrac_57_MVI_63554', 1445),
            57: ('detrac_58_MVI_63561', 1285),
            58: ('detrac_59_MVI_63562', 1185),
            59: ('detrac_60_MVI_63563', 1390),
            # test
            60: ('detrac_61_MVI_39031', 1470),
            61: ('detrac_62_MVI_39051', 1120),
            62: ('detrac_63_MVI_39211', 1660),
            63: ('detrac_64_MVI_39271', 1570),
            64: ('detrac_65_MVI_39311', 1505),
            65: ('detrac_66_MVI_39361', 2030),
            66: ('detrac_67_MVI_39371', 1390),
            67: ('detrac_68_MVI_39401', 1385),
            68: ('detrac_69_MVI_39501', 540),
            69: ('detrac_70_MVI_39511', 380),
            70: ('detrac_71_MVI_40701', 1130),
            71: ('detrac_72_MVI_40711', 1030),
            72: ('detrac_73_MVI_40712', 2400),
            73: ('detrac_74_MVI_40714', 1180),
            74: ('detrac_75_MVI_40742', 1655),
            75: ('detrac_76_MVI_40743', 1630),
            76: ('detrac_77_MVI_40761', 2030),
            77: ('detrac_78_MVI_40762', 1825),
            78: ('detrac_79_MVI_40763', 1745),
            79: ('detrac_80_MVI_40771', 1720),
            80: ('detrac_81_MVI_40772', 1200),
            81: ('detrac_82_MVI_40773', 985),
            82: ('detrac_83_MVI_40774', 950),
            83: ('detrac_84_MVI_40775', 975),
            84: ('detrac_85_MVI_40792', 1810),
            85: ('detrac_86_MVI_40793', 1960),
            86: ('detrac_87_MVI_40851', 1140),
            87: ('detrac_88_MVI_40852', 1150),
            88: ('detrac_89_MVI_40853', 1590),
            89: ('detrac_90_MVI_40854', 1195),
            90: ('detrac_91_MVI_40855', 1090),
            91: ('detrac_92_MVI_40863', 1670),
            92: ('detrac_93_MVI_40864', 1515),
            93: ('detrac_94_MVI_40891', 1545),
            94: ('detrac_95_MVI_40892', 1790),
            95: ('detrac_96_MVI_40901', 1335),
            96: ('detrac_97_MVI_40902', 1005),
            97: ('detrac_98_MVI_40903', 1060),
            98: ('detrac_99_MVI_40904', 1270),
            99: ('detrac_100_MVI_40905', 1710),
        }

        sequences_mnist_mot = {
            # train
            0: ('train_0', 1968),
            1: ('train_1', 1989),
            2: ('train_2', 1994),
            3: ('train_3', 1958),
            4: ('train_4', 1895),
            5: ('train_5', 1962),
            6: ('train_6', 1959),
            7: ('train_7', 1928),
            8: ('train_8', 1991),
            9: ('train_9', 1946),
            10: ('train_10', 1994),
            11: ('train_11', 1982),
            12: ('train_12', 1957),
            13: ('train_13', 1999),
            14: ('train_14', 1964),
            15: ('train_15', 1976),
            16: ('train_16', 1904),
            17: ('train_17', 1913),
            18: ('train_18', 1942),
            19: ('train_19', 1929),
            20: ('train_20', 1982),
            21: ('train_21', 1913),
            22: ('train_22', 1988),
            23: ('train_23', 1890),
            24: ('train_24', 1984),
            # test
            25: ('test_0', 1965),
            26: ('test_1', 1952),
            27: ('test_2', 1938),
            28: ('test_3', 1941),
            29: ('test_4', 1981),
            30: ('test_5', 1941),
            31: ('test_6', 1969),
            32: ('test_7', 1981),
            33: ('test_8', 1959),
            34: ('test_9', 1974),
            35: ('test_10', 1929),
            36: ('test_11', 1999),
            37: ('test_12', 1957),
            38: ('test_13', 1928),
            39: ('test_14', 1976),
            40: ('test_15', 1968),
            41: ('test_16', 2000),
            42: ('test_17', 1998),
            43: ('test_18', 1998),
            44: ('test_19', 1977),
            45: ('test_20', 1923),
            46: ('test_21', 1971),
            47: ('test_22', 1973),
            48: ('test_23', 1992),
            49: ('test_24', 1980),
        }

        # combined GRAM, IDOT, LOST and ISL for convenience of inter-dataset training and testing
        sequences_combined = self.combine_sequences((
            sequences_gram,  # 0 - 2
            sequences_idot,  # 3 - 15
            # sequences_detrac,  # 17 - 116
            # sequences_lost,  # 117 - 118
            # sequences_isl  # 120 - 135
        ))
        sets = {
            0: 'MOT2015',
            1: 'MOT2017',
            2: 'MOT2017_SDP',
            3: 'MOT2017_DPM',
            4: 'KITTI',
            5: 'GRAM_ONLY',
            6: 'IDOT',
            7: 'DETRAC',
            8: 'LOST',
            9: 'ISL',
            10: 'GRAM',  # combined sequence set; named GRAM for convenience
            11: 'MNIST_MOT',
        }
        sequences = dict(
            zip([sets[i] for i in range(len(sets))], [
                sequences_mot2015,
                sequences_mot2017,
                sequences_mot2017_sdp,
                sequences_mot2017_dpm,
                sequences_kitti,
                sequences_gram,
                sequences_idot,
                sequences_detrac,
                sequences_lost,
                sequences_isl,
                sequences_combined,
                sequences_mnist_mot,
            ]))

        ratios_mot2015 = dict(
            zip(range(len(sequences_mot2015)),
                [self.params.ratios_mot2015] * len(sequences_mot2015)))
        ratios_mot2017 = dict(
            zip(range(len(sequences_mot2017)),
                [self.params.ratios_mot2017] * len(sequences_mot2017)))
        ratios_mot2017_sdp = dict(
            zip(range(len(sequences_mot2017_sdp)),
                [self.params.ratios_mot2017_sdp] * len(sequences_mot2017_sdp)))
        ratios_mot2017_dpm = dict(
            zip(range(len(sequences_mot2017_dpm)),
                [self.params.ratios_mot2017_dpm] * len(sequences_mot2017_dpm)))

        ratios_kitti = dict(
            zip(range(len(sequences_kitti)),
                [self.params.ratios_kitti] * len(sequences_kitti)))
        ratios_gram = dict(
            zip(range(len(sequences_gram)),
                [self.params.ratios_gram] * len(sequences_gram)))
        ratios_idot = dict(
            zip(range(len(sequences_idot)),
                [self.params.ratios_idot] * len(sequences_idot)))
        ratios_detrac = dict(
            zip(range(len(sequences_detrac)),
                [self.params.ratios_detrac] * len(sequences_detrac)))
        ratios_lost = dict(
            zip(range(len(sequences_lost)),
                [self.params.ratios_lost] * len(sequences_lost)))
        ratios_isl = dict(
            zip(range(len(sequences_isl)),
                [self.params.ratios_isl] * len(sequences_isl)))
        ratios_mnist_mot = dict(
            zip(range(len(sequences_mnist_mot)),
                [self.params.ratios_mnist_mot] * len(sequences_mnist_mot)))

        ratios_combined = self.combine_sequences((
            ratios_gram,  # 0 - 2
            ratios_idot,  # 3 - 15
            # ratios_detrac,  # 19 - 78
            # ratios_lost,  # 79 - 80
            # ratios_isl  # 81 - 95
        ))
        ratios = dict(
            zip([sets[i] for i in range(len(sets))], [
                ratios_mot2015,
                ratios_mot2017,
                ratios_mot2017_sdp,
                ratios_mot2017_dpm,
                ratios_kitti,
                ratios_gram,
                ratios_idot,
                ratios_detrac,
                ratios_lost,
                ratios_isl,
                ratios_combined,
                ratios_mnist_mot,
            ]))

        return sets, sequences, ratios
class cTestStatus(cSeleniumDriver):

    log = cl.CustomLogger(logging.INFO)

    def __init__(self, driver):
        """
        Inits CheckPoint class
        """
        super(cTestStatus, self).__init__(driver)
        self.lResultList = []

    def SetResult(self, bResult, sResultMessage):
        try:
            if bResult is not None:
                if bResult:
                    self.lResultList.append("PASS")
                    self.log.info("\n")
                    self.log.info("### VERIFICATION SUCCESSFUL :: + " +
                                  sResultMessage)
                    self.log.info("\n")
                else:
                    self.lResultList.append("FAIL")
                    self.log.info("\n")
                    self.log.error("### VERIFICATION FAILED :: + " +
                                   sResultMessage)
                    self.ScreenShot(sResultMessage)
            else:
                self.lResultList.append("FAIL")
                self.log.info("\n")
                self.log.error("### VERIFICATION FAILED :: + " +
                               sResultMessage)
                self.ScreenShot(sResultMessage)
        except:
            self.lResultList.append("FAIL")
            self.log.info("\n")
            self.log.error("### Exception Occurred !!!")
            self.ScreenShot(sResultMessage)
            print_stack()

    def StepResult(self, bResult, sResultMessage):
        """
        Mark the bResult of the verification point in a test case
        """
        self.SetResult(bResult, sResultMessage)

    def FinalResult(self, testName, bResult, sResultMessage):
        """
        Mark the final bResult of the verification point in a test case
        This needs to be called at least once in a test case
        This should be final test status of the test case
        """
        self.SetResult(bResult, sResultMessage)

        if "FAIL" in self.lResultList:
            self.log.info("\n")
            self.log.error(testName + " ### TEST FAILED")
            self.log.info("\n")
            self.lResultList.clear()
            assert True == False
        else:
            self.log.info("\n")
            self.log.info(testName + " ### TEST SUCCESSFUL")
            self.log.info("\n")
            self.lResultList.clear()
            assert True == True
Beispiel #21
0
class Objects:
    """
    set of labeled objects - abstracts out the common components of detections and annotations

    :ivar _params:
    :type _params: Objects.Params
    :ivar _logger:
    :type _logger: CustomLogger
    """
    class Params:
        def __init__(self, name):
            self.path = ''
            self.src_dir = MultiPath(name)
            self.fix_frame_ids = 1
            self.sort_by_frame_ids = 0
            self.ignore_ioa_thresh = 0.5
            self.allow_missing = 0

            self.help = {
                'path':
                'path of the text file in MOT format from where the objects data is to be read;'
                'if this is empty, then a default path is constructed from the sequence and dataset names',
                'fix_frame_ids':
                'convert the frame IDs in the annotations and detections from 1-based '
                '(default MOT challenge format) to 0-based that is needed for internal'
                ' processing convenience',
                'sort_by_frame_ids':
                'sort data by frame IDs',
                'ignored_regions':
                '1: read ignored_regions from annotations; '
                '2: discard the regions after reading'
            }

    def __init__(self, obj_type, params, logger):
        """
        :param str obj_type:
        :param Objects.Params  params:
        :param CustomLogger logger:
        :rtype: None
        """
        self._type = obj_type
        self._params = params
        self._logger = CustomLogger(logger, names=[
            self._type.lower(),
        ])
        self.path = self._params.path

        self.ignored_regions = None
        self.data = None
        self.count = 0
        self.orig_n_frames = 0
        self.start_frame_id = 0
        self.end_frame_id = 0
        self.n_frames = 0
        self.idx = None
        # iou and index of the max iuo detection with each annotation or
        # the max iuo annotation with each detection in each frame
        self.max_cross_iou = None
        self.max_cross_iou_idx = None
        # future extensions
        self.features = None

        self._resize_factor = 1

    def initialize(self, orig_n_frames, start_frame_id=-1, end_frame_id=-1):
        """
        :type orig_n_frames: int
        :type start_frame_id: int
        :type end_frame_id: int
        :rtype: None
        """
        self.orig_n_frames = orig_n_frames
        self.start_frame_id = start_frame_id if start_frame_id >= 0 else 0
        self.end_frame_id = end_frame_id if end_frame_id > 0 else self.orig_n_frames - 1
        self.n_frames = self.end_frame_id - self.start_frame_id + 1

    def _sanity_check(self):
        """
        sanity checks
        """
        """frame IDs"""
        if (self.data[:, 0] < 0).any():
            self._logger.error('Negative frame IDs found in data')
            return False
        """scores"""
        invalid_score_ids = np.where(
            np.logical_or(self.data[:, 6] < 0, self.data[:, 6] > 1))[0]
        if invalid_score_ids.size > 0:
            self._logger.error(
                'Invalid scores outside the range [0, 1] found in data')
            return False
        return True

    def _remove_ignored(self, ignored_regions):
        ioa_1 = np.empty((self.data.shape[0], ignored_regions.shape[0]))
        compute_overlaps_multi(None, ioa_1, None, self.data[:, 2:6],
                               ignored_regions)
        valid_idx = np.flatnonzero(
            np.apply_along_axis(lambda x: np.all(
                np.less_equal(x, self._params.ignore_ioa_thresh)),
                                axis=1,
                                arr=ioa_1))
        n_invalid = self.data.shape[0] - valid_idx.size
        if n_invalid > 0:
            self._logger.info(
                f'Removing {n_invalid} {self._type} having IOA > {self._params.ignore_ioa_thresh} '
                f'with {ignored_regions.shape[0]} ignored regions')
            self.data = self.data[valid_idx, ...]

    def _curtail(self):
        if self.start_frame_id > 0 or self.end_frame_id < self.orig_n_frames - 1:
            self._logger.info('Curtailing data to frames {:d} - {:d}'.format(
                self.start_frame_id, self.end_frame_id))
            valid_idx = np.logical_and(self.data[:, 0] >= self.start_frame_id,
                                       self.data[:, 0] <= self.end_frame_id)
            self.data = self.data[valid_idx, :]
            if self.start_frame_id > 0:
                self.data[:, 0] -= self.start_frame_id

    def _process(self, resize_factor):

        self._resize_factor = resize_factor

        if self._params.sort_by_frame_ids:
            # sort by frame ID
            self._logger.info('sorting by frame IDs')
            self.data = self.data[self.data[:, 0].argsort(kind='mergesort')]

        if self._params.fix_frame_ids:
            # convert frame IDs from 1-based to 0-based
            self._logger.info('converting frame IDs to 0-based')
            self.data[:, 0] -= 1

        if resize_factor != 1:
            self._logger.info('resizing by factor: {}'.format(resize_factor))
            self.data[:, 2:6] *= resize_factor

    def _read(self):
        if not self._params.path:
            raise IOError('Data file path is not provided')

        if not os.path.isfile(self._params.path):
            msg = 'Data file does not exist: {:s}'.format(self._params.path)
            if self._params.allow_missing:
                self._logger.error(msg)
                return False
            else:
                raise IOError(msg)

        self.path = self._params.path
        self._logger.info('Reading from {:s}'.format(self._params.path))
        self.data = np.loadtxt(self._params.path, delimiter=',', ndmin=2)

        return True

    def _build_index(self):
        """
        :rtype: None
        """
        """locations where consecutive frame IDs are not equal
        these are decremented by 1 when compared to the original data vector
        since the vectors being compared are one less in size"""
        end_ids = np.flatnonzero(
            np.not_equal(self.data[1:, 0], self.data[:-1, 0]))

        self.idx = [None] * self.n_frames
        start_id = 0

        for i in range(end_ids.size):
            frame_id = int(self.data[start_id, 0])
            end_id = end_ids[i] + 1
            self.idx[frame_id] = np.arange(start_id, end_id)
            start_id = end_id
        frame_id = int(self.data[start_id, 0])
        self.idx[frame_id] = np.arange(start_id, self.count)

    def _build_index_slow(self):
        """
        :rtype: None
        """
        # must be stable sorting to ensure that the indices for each object are sorted by frame ID
        frame_sort_idx = np.argsort(self.data[:, 0], kind='mergesort')
        sorted_frame_ids = self.data[frame_sort_idx, 0]
        end_ids = np.flatnonzero(
            np.not_equal(sorted_frame_ids[1:], sorted_frame_ids[:-1]))
        self.idx = [None] * self.n_frames
        start_id = 0
        for i in range(end_ids.size):
            frame_id = int(self.data[frame_sort_idx[start_id], 0])
            end_id = end_ids[i] + 1
            self.idx[frame_id] = frame_sort_idx[start_id:end_id]
            start_id = end_id
        frame_id = int(self.data[frame_sort_idx[start_id], 0])
        self.idx[frame_id] = frame_sort_idx[start_id:self.count]
 def enterName(self):
     self.sendText("Bob I.T.", self._enterName, "text")
     cl.allureLogs("Entered Name")
Beispiel #23
0
    def run(data, tester_params, test_params, logger):
        """
        test a trained target
        :type trained_target: Target
        :type data: Data
        :type tester_params: Tester.Params
        :type test_params: Test.Params
        :type logger: logging.RootLogger | logging.logger | CustomLogger
        :type logging_dir: str
        :type args_in: list
        :rtype: bool
        """

        global_logger = logger

        assert test_params.start < len(test_params.seq), f"Invalid start_id: {test_params.start} " \
            f"for {len(test_params.seq)} sequences"

        tester = Tester(tester_params, global_logger)

        success = True
        eval_path = load_dir = None

        evaluate = test_params.evaluate
        eval_dist_type = test_params.eval_dist_type

        results_dir = test_params.results_dir
        results_dir_root = test_params.results_dir_root
        if results_dir_root:
            results_dir = linux_path(results_dir_root, results_dir)

        if test_params.seq_set_info:
            results_dir = linux_path(results_dir, test_params.seq_set_info)

        save_txt = f'saving results to: {results_dir}'
        save_prefix = test_params.save_prefix
        if save_prefix:
            save_txt += f' with save_prefix: {save_prefix}'
        global_logger.info(save_txt)

        n_seq = len(test_params.seq)
        for _id, test_id in enumerate(test_params.seq[test_params.start:]):
            global_logger.info(
                'Running tester on sequence {:d} in set {:d} ({:d} / {:d} )'.
                format(test_id, test_params.seq_set,
                       _id + test_params.start + 1, n_seq))

            if not data.initialize(
                    test_params.seq_set, test_id, 1, logger=global_logger):
                global_logger.error(
                    'Data module failed to initialize with sequence {:d}'.
                    format(test_id))
                success = False
                break

            load_dir = results_dir
            load_prefix = test_params.load_prefix
            if load_prefix:
                load_dir = linux_path(load_dir, load_prefix)

            save_dir = results_dir

            if not os.path.exists(save_dir):
                os.makedirs(save_dir)

            save_prefix = test_params.save_prefix
            if save_prefix:
                save_dir = linux_path(save_dir, save_prefix)

            eval_dir = test_params.eval_dir
            if not eval_dir:
                eval_dir = save_dir
            eval_path = linux_path(eval_dir, test_params.eval_file)

            seq_logger = CustomLogger(global_logger,
                                      names=(data.seq_name, ),
                                      key='custom_header')

            if not tester.initialize(data, seq_logger):
                seq_logger.error(
                    'Tester initialization failed on sequence {:d} : {:s}'.
                    format(test_id, data.seq_name))
                success = False
                break

            if tester.annotations is None:
                seq_logger.warning(
                    'Tester annotations unavailable so disabling evaluation')
                evaluate = 0
            """load existing tracking results and optionally visualize or evaluate"""

            if test_params.subseq_postfix:
                load_fname = '{:s}_{:d}_{:d}.txt'.format(
                    data.seq_name, data.start_frame_id + 1,
                    data.end_frame_id + 1)
            else:
                load_fname = '{:s}.txt'.format(data.seq_name)

            load_path = linux_path(load_dir, load_fname)
            if evaluate:
                if not tester.load(load_path):
                    seq_logger.error(
                        'Tester loading failed on sequence {:d} : {:s}'.format(
                            test_id, data.seq_name))
                    success = False
                    break

            if evaluate:
                eval_dir = test_params.eval_dir
                if not eval_dir:
                    eval_dir = load_dir
                eval_path = linux_path(eval_dir, test_params.eval_file)
                acc = tester.eval(load_path, eval_path, eval_dist_type)
                if not acc:
                    seq_logger.error(
                        'Tester evaluation failed on sequence {:d} : {:s}'.
                        format(test_id, data.seq_name))
                    success = False
                    break
                if evaluate == 2:
                    tester.accumulative_eval(load_dir, eval_path, seq_logger)

            continue

        if evaluate:
            tester.accumulative_eval(load_dir, eval_path, global_logger)

        return success
 def enterEmail(self):
     self.sendText("*****@*****.**", self._enterEmail, "text")
     cl.allureLogs("Entered Email")
Beispiel #25
0
class cProductBook(cSeleniumDriver):
    log = cl.CustomLogger(logging.DEBUG)

    # locators
    sBookTitle = "productTitle"
    sAuthors = "//div[@id='bylineInfo']/span[contains(@class,'author')]"
    sMainAuthor = "./span/a[1]"
    sOtherAuthor = ".//a[1]"
    # sAuthors = "//div[@id='byline']/span[contains(@class,'author')]/span/a[1]"
    # sContributions = "//div[@id='byline']//span[@class = 'contribution']/span"
    sContributions = "//div[@id='bylineInfo']//span[@class = 'contribution']/span"
    sAverageCustomerReview = "//div[@id='averageCustomerReviews']//span[contains(text(),'stars')]"
    sMediaTab = "mediaTabsHeadings"
    sMediaTabHeadings = "//div[@id='mediaTabsHeadings']/ul/li"
    sMediaTabTitle = ".//span[contains(@class,'mediaTab_title')]"
    sMediaTabSubTitle = ".//span[contains(@class,'mediaTab_subtitle')]"
    sSwatches = "tmmSwatches"
    sAnnounces = "//div[@id='tmmSwatches']//span[@class='a-button-inner']"
    sAnnounceTitle = ".//span[1]"
    sAnnounceSubTitle = ".//span[2]/span"

    def __init__(self,driver):
        super(cProductBook, self).__init__(driver)
        self.sTitle = ""
        self.dAuthorInfo = OrderedDict()
        self.sRatings = ""
        self.dBookPrice = OrderedDict()

    # Element Action Methods
    def GetBookTitle(self):
        return self.GetText(self.sBookTitle)

    def GetAuthors(self):
        elAuthors = []
        elAuthorClass = self.GetElementList(self.sAuthors, "xpath", bWaitForElement=True)
        # self.log.info("len of elAuthors : " + str(len(elAuthorClass)))
        for eAuthorClass in elAuthorClass:
            eAuthor = self.GetElement(self.sMainAuthor, "xpath", element=eAuthorClass, isLog=False)
            if eAuthor is None:
                eAuthor = self.GetElement(self.sOtherAuthor, "xpath", element=eAuthorClass)
            elAuthors.append(eAuthor)

        return elAuthors

    def GetContributions(self):
        return self.GetElementList(self.sContributions, "xpath", bWaitForElement=True)

    def GetAverageCustomerReview(self):
        return self.GetText(self.sAverageCustomerReview, "xpath")

    def GetMediaTab(self):
        return self.GetElement(self.sMediaTab, isLog=False)

    def GetMediaTabHeadings(self):
        elMediaTabHeadings = None
        eMediaTab = self.GetMediaTab()
        if eMediaTab != None:
            elMediaTabHeadings = self.GetElementList(self.sMediaTabHeadings,"xpath",)

        return elMediaTabHeadings

    def GetSwatches(self):
        return self.GetElement(self.sSwatches)

    def GetAnnounces(self):
        elAnnounces = None
        eSwatches = self.GetSwatches()
        if eSwatches != None:
            elAnnounces = self.GetElementList(self.sAnnounces, "xpath")

        return elAnnounces

    # Functionality Methods
    def GetBookInfo(self):
        self.sTitle = self.GetBookTitle()
        elAuthors = self.GetAuthors()
        elContributions = list(self.GetContributions())
        # self.log.info("len of elcontribution : " + str(len(elContributions)))
        for (eAuthor, eContribution) in zip(elAuthors,elContributions):
            self.dAuthorInfo[self.GetText(element=eAuthor)] = self.GetText(element=eContribution)

        return self.sTitle, self.dAuthorInfo

    def GetBookPrice(self):
        elMediaTabHeadings = self.GetMediaTabHeadings()
        if elMediaTabHeadings != None and len(elMediaTabHeadings) >= 1:
            for eHeading in elMediaTabHeadings:
                if self.IsElementDisplayed(element=eHeading):
                    eMediaTabTitle = self.GetElement(self.sMediaTabTitle, "xpath", eHeading)
                    sMediaTabTitle = self.GetText(element=eMediaTabTitle)
                    ePrice = self.GetElement(self.sMediaTabSubTitle, "xpath", eHeading)
                    sPrice = self.GetText(element=ePrice)
                    self.dBookPrice[sMediaTabTitle] = sPrice
        else:
            elAnnounces = self.GetAnnounces()
            if elAnnounces != None and len(elAnnounces) >= 1:
                for eAnnounce in elAnnounces:
                    if self.IsElementDisplayed(element=eAnnounce):
                        eAnnounceTitle = self.GetElement(self.sAnnounceTitle, "xpath", eAnnounce)
                        sAnnounceTitle = self.GetText(element=eAnnounceTitle)
                        ePrice = self.GetElement(self.sAnnounceSubTitle, "xpath", eAnnounce)
                        sPrice = self.GetText(element=ePrice)
                        self.dBookPrice[sAnnounceTitle] = sPrice

        return self.dBookPrice

    def GetBookRatings(self):
        self.sRatings = self.GetAverageCustomerReview()
        self.WebScroll("down", "-200")
        return self.sRatings
 def enterAddress(self):
     self.sendText("Turkey", self._enterAddress, "text")
     cl.allureLogs("Entered Address")
Beispiel #27
0
class RegisterCoursesPage(BasePage):
    log = cl.CustomLogger(logging.DEBUG)

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

    # locators
    _login_button = "//*[@name='commit']"
    _search_box = "//*[@id='search-courses']"
    _course = "//div[@data-course-id='56740']"
    _enroll_button = "//button[@id='enroll-button-top']"
    _cc_num = "//div//span//div//input[@name='cardnumber']"
    _cc_exp = "//input[@name='exp-date']"
    _cc_cvv = "//input[@name='cvc']"
    _cc_post = "//input[@name='postal']"
    _terms_checkbox = "//input[@id='agreed_to_terms_checkbox']"
    _submit_enroll = "//label[@for='spc-primary-submit']"
    _enroll_error_message = "//div[@class='payment-error-box only-on-mobile']"


    def enterCourseName(self, name):
        self.sendKeys(name, self._search_box)
        cCN = self.getElement("//div[contains(text(),'" + name + "')]")
        cCN.click()

    def clickEnrollButton(self):
        self.clickElement(self._enroll_button)

    def creditCardNumber(self, num):
        self.switchToFrame("//iframe[@name='__privateStripeFrame12']")
        self.waitForElement(self._cc_num)
        self.webScroll(self._cc_num)
        self.sendKeys(num, self._cc_num)
        self.driver.switch_to.default_content()

    def creditCardExp(self, exp):
        self.switchToFrame("//iframe[@name='__privateStripeFrame13']")
        self.waitForElement(self._cc_exp)
        self.sendKeys(exp, self._cc_exp)
        self.driver.switch_to.default_content()

    def creditCardCVV(self, cvv):
        self.switchToFrame("//iframe[@name='__privateStripeFrame14']")
        self.waitForElement(self._cc_cvv)
        self.sendKeys(cvv, self._cc_cvv)
        self.driver.switch_to.default_content()

    def cityPost(self, post):
        self.switchToFrame("//iframe[@name='__privateStripeFrame15']")
        #self.SwitchFrameByIndex(self._cc_post)
        self.waitForElement(self._cc_post)
        self.sendKeys(post, self._cc_post)
        self.driver.switch_to.default_content()

    def enterCreditCardInfo(self, num, exp, cvv, post):
        self.creditCardNumber(num)
        self.creditCardExp(exp)
        self.creditCardCVV(cvv)
        self.cityPost(post)

    def clickTermsCheckbox(self):
        self.clickElement(self._terms_checkbox)

    def clickEnrollSubmitButton(self):
        self.clickElement(self._submit_enroll)

    def verifyEnrollFailed(self):
        verify = self.isElementPresent('//button[@class="btn btn-primary spc__button is-disabled"]')
        return verify
 def enterMNumber(self):
     self.sendText("573654210", self._enterMobileNumber, "index")
     cl.allureLogs("Entered Mobile Number")
class SeleniumDriver():

    log = cl.customLogger(logging.DEBUG)

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

    def screenShot(self, resultMessage):
        """
        Takes screenshot of the current open web page
        """
        fileName = resultMessage + "." + str(round(
            time.time() * 1000)) + ".png"
        screenshotDirectory = "../screenshots/"
        relativeFileName = screenshotDirectory + fileName
        currentDirectory = os.path.dirname(__file__)
        destinationFile = os.path.join(currentDirectory, relativeFileName)
        destinationDirectory = os.path.join(currentDirectory,
                                            screenshotDirectory)

        try:
            if not os.path.exists(destinationDirectory):
                os.makedirs(destinationDirectory)
            self.driver.save_screenshot(destinationFile)
            self.log.info("Screenshot save to directory: " + destinationFile)
        except:
            self.log.error("### Exception Occurred when taking screenshot")
            print_stack()

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

    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:
            self.log.info("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 with locator: " + locator +
                          " and  locatorType: " + locatorType)
        except:
            self.log.info("Element not found with locator: " + locator +
                          " and  locatorType: " + locatorType)
        return element

    def getElementList(self, locator, locatorType="id"):
        """
        NEW METHOD
        Get list of elements
        """
        element = None
        try:
            locatorType = locatorType.lower()
            byType = self.getByType(locatorType)
            element = self.driver.find_elements(byType, locator)
            self.log.info("Element list found with locator: " + locator +
                          " and locatorType: " + locatorType)
        except:
            self.log.info("Element list not found with locator: " + locator +
                          " and locatorType: " + locatorType)
        return element

    def elementClick(self, locator="", locatorType="id", element=None):
        """
        Click on an element -> MODIFIED
        Either provide element or a combination of locator and locatorType
        """
        try:
            if locator:  # This means if locator is not empty
                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", element=None):
        """
        Send keys to an element -> MODIFIED
        Either provide element or a combination of locator and locatorType
        """
        try:
            if locator:  # This means if locator is not empty
                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 clearField(self, locator="", locatorType="id"):
        """
        Clear an element field
        """
        element = self.getElement(locator, locatorType)
        element.clear()
        self.log.info("Clear field with locator: " + locator +
                      " locatorType: " + locatorType)

    def getText(self, locator="", locatorType="id", element=None, info=""):
        """
        NEW METHOD
        Get 'Text' on an element
        Either provide element or a combination of locator and locatorType
        """
        try:
            if locator:  # This means if locator is not empty
                element = self.getElement(locator, locatorType)
            text = element.text
            if len(text) == 0:
                text = element.get_attribute("innerText")
            if len(text) != 0:
                self.log.info("Getting text on element :: " + info)
                self.log.info("The text is :: '" + text + "'")
                text = text.strip()
        except:
            self.log.error("Failed to get text on element " + info)
            print_stack()
            text = None
        return text

    def isElementPresent(self, locator="", locatorType="id", element=None):
        """
        Check if element is present -> MODIFIED
        Either provide element or a combination of locator and locatorType
        """
        try:
            if locator:  # This means if locator is not empty
                element = self.getElement(locator, locatorType)
            if element is not None:
                self.log.info("Element present with locator: " + locator +
                              " locatorType: " + locatorType)
                return True
            else:
                self.log.info("Element not present with locator: " + locator +
                              " locatorType: " + locatorType)
                return False
        except:
            print("Element not found")
            return False

    def isElementDisplayed(self, locator="", locatorType="id", element=None):
        """
        NEW METHOD
        Check if element is displayed
        Either provide element or a combination of locator and locatorType
        """
        isDisplayed = False
        try:
            if locator:  # This means if locator is not empty
                element = self.getElement(locator, locatorType)
            if element is not None:
                isDisplayed = element.is_displayed()
                self.log.info("Element is displayed")
            else:
                self.log.info("Element not displayed")
            return isDisplayed
        except:
            print("Element not found")
            return False

    def elementPresenceCheck(self, locator, byType):
        """
        Check if element is present
        """
        try:
            elementList = self.driver.find_elements(byType, locator)
            if len(elementList) > 0:
                self.log.info("Element present with locator: " + locator +
                              " locatorType: " + str(byType))
                return True
            else:
                self.log.info("Element not present with locator: " + locator +
                              " locatorType: " + str(byType))
                return False
        except:
            self.log.info("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=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

    def webScroll(self, direction="up"):
        """
        NEW METHOD
        """
        if direction == "up":
            # Scroll Up
            self.driver.execute_script("window.scrollBy(0, -1000);")

        if direction == "down":
            # Scroll Down
            self.driver.execute_script("window.scrollBy(0, 1000);")
 def clickSubmitButton(self):
     self.clickElement(self._submitButton, "text")
     cl.allureLogs("Clicked on Submit button")