这个类我存储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();
}
}
我的理解。 1)驱动程序对象创建在Stepdefinition中2)webdriverUtillfuncalss中的所有驱动程序函数,如wait,click,sendkeys等
另一种方法是将webdriverUtillfuncalss中的方法设置为静态。所以你不需要创建webdriverUtillfuncalss对象。还将驱动程序对象作为参数发送到webdriverUtillfuncalss中的每个方法。