コード例 #1
0
def priceVerification(drop_down_item, random_price):
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    table_rows = getChildren(driver, "tbody", "tr", "tag", "tag")
    if len(table_rows) == 0:
        BuiltIn().log(
            "Unable to extract rows ===> No rows found with the givin price",
            level="error")
        assert True == False
    result = True
    for j in range(len(table_rows)):
        columns = getChildren(driver,
                              childrenlocator="td",
                              childrenlocatorType="tag",
                              parent=table_rows[j])
        if len(columns) == 0:
            BuiltIn().log("Unable to extract columns in row number " +
                          str(j + 1))
            continue
        price_index = getPriceIndex(driver)
        price = columns[price_index].text
        if price == "":
            BuiltIn().log("Price is empty in company number " + str(j + 1),
                          level="error")
            result = False
        else:
            if compare(drop_down_item, price, random_price):
                BuiltIn().log("Price in row " + str(j + 1) +
                              " is accurate ==>" + price)
            else:
                BuiltIn().log("Price in row " + str(j + 1) +
                              " is not accurate ==>" + price,
                              level="error")
                result = False
    return result
コード例 #2
0
def getAllPrices():
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    table_rows = getChildren(driver, "tbody", "tr", "tag", "tag")
    if len(table_rows) == 0:
        BuiltIn().log("Unable to extract rows", level="error")
        assert True == False
    prices = []
    for j in range(len(table_rows)):
        columns = getChildren(driver,
                              childrenlocator="td",
                              childrenlocatorType="tag",
                              parent=table_rows[j])
        if len(columns) == 0:
            BuiltIn().log("Unable to extract columns in row number " +
                          str(j + 1))
            continue
        price_index = getPriceIndex(driver)
        price = columns[price_index].text
        if price == "":
            BuiltIn().log("Price is empty in company number " + str(j + 1),
                          level="error")
        else:
            prices.append(price)
    return prices
コード例 #3
0
def verifyIndestries(driver, liste):
    number_tries_indestries = 0
    indestries_found = False
    while (number_tries_indestries < 5):
        number_tries_indestries += 1
        if iselementClick(driver, element=liste[1]):
            BuiltIn().log("element is clicked")
            indestries_list = getChildren(driver,
                                          "select2-results__options",
                                          "li",
                                          parentlocatorType="class")
            if len(indestries_list) > 0:
                BuiltIn().log(
                    str(len(indestries_list)) +
                    " indestries found in this sector")
                indestries_found = True
                break
            else:
                continue
        else:
            BuiltIn().log("Unable to clcik element")
            continue
    if indestries_found == False:
        BuiltIn().log("No indestries found in this sector", level="error")
    return indestries_found
コード例 #4
0
def selectCountry(country_name):
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    number_tries = 0
    selected = False
    while (number_tries <= 5):
        number_tries += 1
        if iselementClick(driver,
                          locator="//span[@role='combobox']",
                          locatorType="xpath"):
            countries_list = getChildren(driver,
                                         "select2-results__options",
                                         "li",
                                         parentlocatorType="class")
            if len(countries_list) > 1:
                for i in range(len(countries_list)):
                    if countries_list[i].text == country_name:
                        index = i
                        break
                if iselementClick(driver, element=countries_list[index]):
                    BuiltIn().log(country_name + " is selected successfully")
                    selected = True
                    break
                else:
                    continue
            else:
                continue

        else:
            continue
    if selected == False:
        BuiltIn().log("Unable to select country " + country_name,
                      level="error")
    assert selected == True
コード例 #5
0
def getNumberPages():
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    pagination_elements = getChildren(driver,
                                      parentlocator="result-details",
                                      parentlocatorType="id",
                                      childrenlocator="li",
                                      childrenlocatorType="tag")
    if len(pagination_elements) == 0:
        BuiltIn().log("Unable to extract pagination elements", level="error")
        assert False == True
    pagination_elements.pop(0)
    pagination_elements.pop(-1)
    pagination_numbers = []
    for p in pagination_elements:
        if str(p.text).isdigit():
            pagination_numbers.append(p.text)
    useful_pagination_numbers = []
    if len(pagination_numbers) >= 3:
        useful_pagination_numbers.append(
            pagination_numbers[(len(pagination_numbers) - 1) // 2])
        useful_pagination_numbers.append(pagination_numbers[-1])
    elif len(pagination_numbers) == 2:
        useful_pagination_numbers.append(pagination_numbers[-1])
    elif len(pagination_numbers) == 0:
        BuiltIn().log(
            "No digital numbers found in the bottom pagination  ====> Page is empty",
            level="error")
        assert False == True
    return useful_pagination_numbers
コード例 #6
0
def VerifyPortfloioDontContainRepeatedRows():
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    try:
        row_list = getElementList(driver, locator="tr", locatorType="tag")
        i = 1
        repeated = False
        company_dictionnary = dict()
        for row in row_list:
            column_liste = getChildren(driver,
                                       childrenlocator="td",
                                       childrenlocatorType="tag",
                                       parent=row)
            company_name = str(column_liste[0].text)
            if company_name in company_dictionnary:
                company_dictionnary[company_name] = -1
                repeated = True
            else:
                company_dictionnary[company_name] = i
            i += 1
    except:
        BuiltIn().log(
            "A problem accured while verifying there's no repetetion")
    if repeated:
        BuiltIn().log("The portfolio contains repeated rows", level="error")
    for key, value in company_dictionnary.items():
        if value == -1:
            BuiltIn().log("The company " + key +
                          "is repeated in the portfolio")
    assert repeated == False
コード例 #7
0
def getNumberFilters():
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    nb_filters = getChildren(driver,
                             parentlocator="additional-filters",
                             parentlocatorType="class",
                             childrenlocator="tr",
                             childrenlocatorType="tag")
    return len(nb_filters)
コード例 #8
0
def getPriceIndex(driver):
    try:
        table_titles_elements = getChildren(driver,
                                            parentlocator="thead",
                                            parentlocatorType="tag",
                                            childrenlocator="th",
                                            childrenlocatorType="tag")
        for i in range(len(table_titles_elements)):
            title = table_titles_elements[i].text
            if title == "Price":
                return i
    except:
        return 4
コード例 #9
0
def verifyPageNotEmpty():
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    childrenlist = getChildren(driver,
                               parentlocator="app-company-detail",
                               childrenlocator="div",
                               parentlocatorType="tag",
                               childrenlocatorType="tag")
    if len(childrenlist) == 0:
        BuiltIn().log("Page is empty", level="error")
        return True
    else:
        return False
コード例 #10
0
def getHeader(driver):
    try:
        table_titles = []
        table_titles_elements = getChildren(driver,
                                            parentlocator="thead",
                                            parentlocatorType="tag",
                                            childrenlocator="th",
                                            childrenlocatorType="tag")
        table_titles_elements.pop(-1)
        for e in table_titles_elements:
            table_titles.append(e.text)
    except:
        table_titles = ["Symbol", "Price", "Change", "Change %", "Quantity"]
        BuiltIn().log("Unable to extract the header of the portfolio")
    return table_titles
コード例 #11
0
def verifyMyPortfolioNotEmpty():
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    table_titles = getHeader(driver)
    try:
        row_list = getElementList(driver, locator="tr", locatorType="tag")
    except:
        empty = True
        BuiltIn().log("Can not extract rows", level="error")
    if len(row_list) != 0:
        BuiltIn().log("Number of elements in portfolio: " + str(len(row_list)))
        i = 1
        empty = False
        for row in row_list:
            try:
                column_liste = getChildren(driver,
                                           childrenlocator="td",
                                           childrenlocatorType="tag",
                                           parent=row)
            except:
                BuiltIn().log("Can not extract columns in row number " +
                              str(i))
            if len(column_liste) != 0:
                column_liste.pop(-1)
                j = 0
                for column in column_liste:
                    if column.text == "":
                        empty = True
                        BuiltIn().log("********Company " + str(i) +
                                      "*********")
                        try:
                            BuiltIn().log(table_titles[j] + " is empty")
                        except:
                            BuiltIn().log("A column in this list is empty")
                    j += 1
                i += 1
            else:
                empty = True
                BuiltIn().log("No columns found in row number " + str(i))
                i += 1
    else:
        empty = True
        BuiltIn().log("No rows found", level="error")
    if empty:
        BuiltIn().log("Some items are missing in the portfolio", level="error")
    else:
        BuiltIn().log("All items are accurate in the portfolio")
    assert empty == False
コード例 #12
0
def clickSectorInputField(driver, liste):
    number_tries = 0
    while (number_tries <= 5):
        number_tries += 1
        if iselementClick(driver, element=liste[0]):
            sectors_list = getChildren(driver,
                                       "select2-results__options",
                                       "li",
                                       parentlocatorType="class")
            if len(sectors_list) > 0:
                break
            else:
                continue
        else:
            continue
    return sectors_list
コード例 #13
0
def isDropDownItemClicked():
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    try:
        serach_results_elements = getChildren(
            driver,
            parentlocator="typeahead-container",
            childrenlocator="button",
            parentlocatorType="tag",
            childrenlocatorType="tag")
        elementClick(driver, element=serach_results_elements[0])
        BuiltIn().log("Drop down item is clicked successfully")
        return True
    except:
        BuiltIn().log("can not click drop down item", level="error")
        return False
コード例 #14
0
def changePassword(old_password, new_password):
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    parent = getElement(driver,
                        locator="//tab[@heading='Password']",
                        locatorType="xpath")
    inputs_list = getChildren(driver,
                              childrenlocator="input",
                              childrenlocatorType="tag",
                              parent=parent)
    data_is_sent = False
    if sendKeys(driver, element=inputs_list[0], data=old_password):
        if sendKeys(driver, element=inputs_list[1], data=new_password):
            if sendKeys(driver, element=inputs_list[2], data=new_password):
                data_is_sent = True
            else:
                BuiltIn().log("Unable to send data in the third firld",
                              level="error")
        else:
            BuiltIn().log("Unable to send data in the second field",
                          level="error")
    else:
        BuiltIn().log("Unable to send data in the first field", level="error")
    assert data_is_sent == True
コード例 #15
0
def verifyResults(halal):
    se2lib = BuiltIn().get_library_instance("Selenium2Library")
    driver = se2lib._current_browser()
    table_titles = [
        "Add to Portfolio", "Symbol", "Name", "Exchange", "Price", "Pass/Fail"
    ]
    table_rows = getChildren(driver, "tbody", "tr", "tag", "tag")
    if len(table_rows) == 0:
        BuiltIn().log("Unable to extract rows", level="error")
        assert True == False
    result = True
    for j in range(len(table_rows)):
        columns = getChildren(driver,
                              childrenlocator="td",
                              childrenlocatorType="tag",
                              parent=table_rows[j])
        if len(columns) == 0:
            BuiltIn().log("Unable to extract columns in row number " +
                          str(j + 1))
            continue
        BuiltIn().log("Number of columns")
        BuiltIn().log("### Company number " + str(j + 1) + "###")
        for i in range(len(columns)):
            if table_titles[i] == "Add to Portfolio":
                continue
            elif table_titles[i] == "Pass/Fail":
                number_tries = 0
                while (number_tries < 5):
                    number_tries += 1
                    pass_fail_text = str(columns[i].text).replace("\n", " ")
                    if pass_fail_text != "":
                        break
                if pass_fail_text == "":
                    BuiltIn().log(table_titles[i] +
                                  " is empty in company number " + str(j + 1),
                                  level="error")
                    result = False
                elif halal:
                    if ("Pass" not in pass_fail_text):
                        BuiltIn().log(
                            "pass_fail_text has a wrong syntax ===> " +
                            pass_fail_text)
                    else:
                        BuiltIn().log(table_titles[i] +
                                      " is not empty and is accurate" +
                                      "===>" + pass_fail_text)
                else:
                    if ("Fail" not in pass_fail_text) & (
                            "Pass" not in pass_fail_text) & (
                                "Missing Data" not in pass_fail_text):
                        BuiltIn().log(
                            "pass_fail_text has a wrong syntax ===> " +
                            pass_fail_text)
                    else:
                        BuiltIn().log(table_titles[i] +
                                      " is not empty and is accurate" +
                                      "===>" + pass_fail_text)
            else:
                column_text = columns[i].text
                if column_text != "":
                    BuiltIn().log(table_titles[i] + " is not empty" + "===>" +
                                  column_text)
                else:
                    BuiltIn().log(table_titles[i] +
                                  " is empty in company number " + str(j + 1),
                                  level="error")
                    result = False
    return result