0

I am currently testing the orangehrmdemo site. I am executing the following scenario: Step 1: login Step 2: click the My Info button Step 3: enter information. However, at the step of selecting nationality, I can scroll but cannot click, but the testcase still passes

Here is my code.

function myInfoPage(){
    let page = {}
    let locators = {
        "txt_FirstName":"//input[@name = 'firstName']",
        "txt_MiddleName":"//input[@name = 'middleName']",
        "txt_LastName": "//input[@name = 'lastName']",
        "txt_NickName": "//label[text()='Nickname']/parent::div/parent::div//child::input",
        "txt_EmployeeId" : "//label[text()='Employee Id']/parent::div/parent::div//child::input",
        "txt_OtherId": "//label[text()='Other Id']/parent::div/parent::div//child::input",
        "txt_DriverLicenseNumber":"//label[contains(text(), 'Driver')]/parent::div/parent::div//child::input",
        "txt_LicenseExpiryDate":"//label[text()='License Expiry Date']/parent::div/parent::div//child::input",
        "txt_SSNNumber": "//label[text()='SSN Number']/parent::div/parent::div//child::input",
        "txt_SINNumber": "//label[text()='SIN Number']/parent::div/parent::div//child::input",
        "cmb_Nationality": "//label[text()='Nationality']//parent::div//following-sibling::div",
        "cmb_MaritalStatus": "//label[text()='Marital Status']//parent::div//following-sibling::div",
        "txt_DateOfBirth": "//label[text() = 'Date of Birth']//parent::div//parent::div//child::input",
        "rdo_Male": "//label[text()='Gender']//parent::div//parent::div//child::input[@value='1']",
        "rdo_Female": "//label[text()='Gender']//parent::div//parent::div//child::input[@value='2']",
        "txt_MilitaryService": "//label[text()='Military Service']/parent::div/parent::div//child::input",
        "chk_Smoker": "//label[text()='Smoker']/parent::div/parent::div//child::input",
        "btn_Save": "//p[text()=' * Required']//parent::div//child::button",
        "icon_Loading": "//div[@class = 'oxd-loading-spinner']",
        "msg_Success": "//div[@class = 'oxd-toast oxd-toast--success oxd-toast-container--toast']//child::p[text() = 'Successfully Updated']",

    }

    //Init MyInfo Page locator
    page.locators = locators

    //Clear and input for TextBox
    const doClearAndInputText = function(locator, textInput){
        try{
            retry(5,1000).waitForEnabled(locator)
            input(locator, Key.CONTROL + "A" + Key.BACK_SPACE)
            input(locator, textInput, 100)
            enterText = value(locator)
            karate.log("Text " + enterText + "was input in " + locator)
        }
        catch(e){
            karate.fail(e.message)
            karate.log("Text " + enterText + "couldn't input in " + locator)
        }
    }

    const enterFirstName = function (firstName){
        doClearAndInputText(locators.txt_FirstName, firstName)
    }

    const enterMiddleName = function (middleName){
        doClearAndInputText(locators.txt_MiddleName, middleName)
    }

    const enterLastName = function (lastName){
        doClearAndInputText(locators.txt_LastName, lastName)
    }

    const enterEmployeeId = function (employeeId){
        doClearAndInputText(locators.txt_EmployeeId, employeeId)
    }

    const enterOtherId = function (otherId){
        doClearAndInputText(locators.txt_OtherId, otherId)
    }

    const enterDriverLicenseNumber = function(driverLicenseNumber){
        doClearAndInputText(locators.txt_DriverLicenseNumber, driverLicenseNumber)
    }

    const enterLicenseExpireDate = function(licenseExpireDate){
        doClearAndInputText(locators.txt_LicenseExpiryDate, licenseExpireDate)
    }

    const enterDateOfBirth = function(dateOfBirth){
        doClearAndInputText(locators.txt_DateOfBirth,dateOfBirth)
    }

    const selectGender = function(gender){
        if(gender.toLowerCase() == "male"){
            retry(5,1000).waitForEnabled(locators.rdo_Male).click()
        }
        else if(gender.toLowerCase() == "female"){
             retry(5,1000).waitForEnabled(locators.rdo_Female).click()
        }
        else{
            karate.fail("Data gender is invalid")
        }
    }

    const clickCmbNationality = function(nationality){
        try{
            let option_Nationality = "//label[text()='Nationality']//parent::div//following-sibling::div//span[contains(text(), '" + nationality + "')]"
            karate.log(option_Nationality)
            retry(5,1000).waitForEnabled(locators.cmb_Nationality)
            mouse().move(locators.cmb_Nationality).click()
//            retry(5,1000).waitForEnabled(option_Nationality)
//            mouse(option_Nationality).click()
            retry(5,1000).waitForEnabled("//label[text()='Nationality']//parent::div//following-sibling::div//div[@role = 'listbox']")
            mouse("//label[text()='Nationality']//parent::div//following-sibling::div//div[@role = 'listbox']")
            scroll(option_Nationality)
            delay(5000)
            screenshot()
            try{
                retry(5,1000).waitForEnabled(option_Nationality)
                mouse().move(option_Nationality).click()
                karate.log(text("//label[text()='Nationality']//parent::div//following-sibling::div//div[@class = 'oxd-select-text-input'][1]"))
                return option_Nationality
            }
            catch(e){
                karate.log("Element in listbox can't click")
                return null
            }
        }
        catch(e){
            karate.log('Something error')
            return null
        }
    }

    const selectNationality = function(nationality){
        karate.log(nationality)
        retry(5,1000).waitUntil(function(){return clickCmbNationality(nationality)})
        screenshot()
    }

    page.enterUserInformation = function(data){
        data.first_name != null ? enterFirstName(data.first_name) : karate.fail("FirstName not found")
        data.middle_name != null ? enterMiddleName(data.middle_name) : karate.fail("MiddleName not found")
        data.last_name != null ? enterLastName(data.last_name) : karate.fail("LastName not found")
        data.employee_id != null ? enterEmployeeId(data.employee_id) : karate.fail("EmployeeId not found")
        data.other_id != null ? enterOtherId(data.other_id) : karate.fail("OtherId not found")
        data.driver_license_number != null ? enterDriverLicenseNumber(data.driver_license_number) : karate.fail("Driver license number not found")
        data.license_expire_date != null ? enterLicenseExpireDate(data.license_expire_date) : karate.fail("License expire date not found")
        data.date_of_birth != null ? enterDateOfBirth(data.date_of_birth) : karate.fail("Date of birth not found")
        data.gender != null ? selectGender(data.gender) : karate.fail("Gender not found")
        data.nationality != null ? selectNationality(data.nationality) : karate.fail("Nationality not found")
    }
    return page;
}

Here is my evidence [1]: https://i.sstatic.net/Wl2CBpwX.png

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.