我应该如何将“public static final By”类型值作为参数传递。下面是示例代码

问题描述 投票:0回答:1

这个类我存储XPath并保存为public static final By类型变量。

class page { 
    public static final By signInTab = By.xpath("//a[contains(text(),'Sign In')][1]"); 
    public static final By emailAddress = By.id("login");
}

我将使用测试运行此类,这是一个示例代码,主要的moto是从页面类获取XPath并在webdriverUtillfuncalss类中传递它

class stepdefinations { 
    //creating the object of webdriver class and using different method to perform webdriver operations 
    webdriverUtillfuncalss lib=new webdriverUtillfuncalss(); 
    //please conform whether its correct to pass it here 
    lib.mouseHovertoElement(page.emailAddress);

}

我怀疑这可能是错误的传递方式,请建议

class webdriverUtillfuncalss {
    public void mouseHovertoElement(By element) {
        Actions mouseho=new Actions(driver);
        mouseho.moveToElement(driver.findElement(element)).build().perform();
    }
}
java selenium
1个回答
0
投票

我的理解。 1)驱动程序对象创建在Stepdefinition中2)webdriverUtillfuncalss中的所有驱动程序函数,如wait,click,sendkeys等

另一种方法是将webdriverUtillfuncalss中的方法设置为静态。所以你不需要创建webdriverUtillfuncalss对象。还将驱动程序对象作为参数发送到webdriverUtillfuncalss中的每个方法。

© www.soinside.com 2019 - 2024. All rights reserved.