mardi 21 février 2017

Geb/Spock: How can common utility functions be defined for page elements

I have defined one element in my page class like:

class myPage extends Page{
.....
static content = {
parentDivAllPassangerInfo(wait:true) { $("div",class:'input_block  passenger_info')}
}
....
}

Than when browser is at this page, I am getting this element like:

when:"Passanger Information Page Opened"
            Thread.sleep(moderateWaittime)          
            at PassangerInformationPage
            println parentDivAllPassangerInfo.getAt(0).size()  // Shows: 1
            println parentDivAllPassangerInfo.getAt(0).getClass().getName() //  Shows: geb.navigator.NonEmptyNavigator

Now I created a utility class where common function like Click()/wait() for example will be performed on any element like below:

import geb.navigator.Navigator;
import geb.navigator.NonEmptyNavigator
import geb.waiting.Wait;
import geb.Browser;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement

public class WaitForElementUntilVisible {
    public static boolean waitUntilElementIsVisible(Navigator element){

        while(!element.present && !element.size() > 0)
        {
            ......          
        }
        return true;
    }

}

However when I call this function in then block,

WaitForElementUntilVisible.waitUntilElementIsVisible(parentDivAllPassangerInfo.getAt(0))

 it get exception:

java.lang.NullPointerException: Cannot get property 'element' on null object
    at navigationUtils.WaitForElementUntilVisible.waitUntilElementIsVisible(WaitForElementVisibility.groovy:12)
    at com.skygate.global.HomePageTest.Open Homepage(HomePageTest.groovy:127)

I tried other ways as well but could not use the above utility function. How I can use this utility function?

Aucun commentaire:

Enregistrer un commentaire