jeudi 19 septembre 2019

Set up a selenium basepage and Web Driver factory for kobition devices

I have quite a complicated regarding my selenium base pages. I currently have a structure when my website pages which house the methods, functions and elements extend a base page:

public abstract class BasePage {
protected static final int WAIT_FOR_PAGE_LOAD_IN_SECONDS = 5;
/**
 * In subclasses  should be used for page opening
 */
protected abstract void openPage();

/**
 * checks is page opened
 * @return true if opened
 */
public abstract boolean isPageOpened();

public BasePage(boolean openPageByUrl){
    if(openPageByUrl){
        openPage();
    }
    PageFactory.initElements(getDriver(), this);
    waitForOpen();
}

/**
 * Waiting for page opening
 */
protected void waitForOpen(){
    int secondsCount = 0;
    boolean isPageOpenedIndicator = isPageOpened();
    while (!isPageOpenedIndicator && secondsCount < WAIT_FOR_PAGE_LOAD_IN_SECONDS) {
        TimeUtils.waitForSeconds(1);
        secondsCount++;
        isPageOpenedIndicator = isPageOpened();
    }
    if(!isPageOpenedIndicator) {
        throw new AssertionError("Page was not opened");
    }
}

/**
 * getting webdriver instance
 * @return initialized in tests webdriver instance
 */
protected org.openqa.selenium.WebDriver getDriver(){
    return Drivers.getDriver();
}

}

and all my test pages extend a page factory

public class ConditionsWebDriverFactory {

@BeforeClass
public void beforeTest() {
    Drivers.startBrowser(true);
    Drivers.getDriver().manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    Drivers.getDriver().manage().window().maximize();


}

@AfterClass (alwaysRun = true)
public void afterTest() {
    Drivers.finishBrowser();

}
}

The problem im having is that these all open a chromedriver so all these tests basiclaly become obsolete when im using the capabilities from kobition, is there a way i could even create a base page and driverfactory for a mobile emulator so i dont have to keep stating the capabiltites in each test?

Aucun commentaire:

Enregistrer un commentaire