老师你好,想问一下BasePage的方法可不可以用静态?
来源:7-3 登陆代码分层设计之page和BasePage实现

慕田峪8226962
2020-03-14
我的想法就是在LoginPage通过调用BasePage.GetElement(WebDriver driver, String key)这样传进来,不想通过构造方法这样子传进来,这样会不会有问题?代码在下面,谢谢。
public class BasePage {
public static WebElement getElement(WebDriver driver, String key) throws IOException {
return driver.findElement(getByLocal(key));
}
public static By getByLocal(String key) throws IOException {
InputStream ips = Base.class.getClassLoader().getResourceAsStream("elements.properties");
Properties properties = new Properties();
properties.load(ips);
String locator = properties.getProperty(key);
String locateBy = locator.split(">")[0];
String locateValue = locator.split(">")[1];
if (locateBy.equals("id")) {
return By.id(locateValue);
} else if (locateBy.equals("name")) {
return By.name(locateValue);
} else if (locateBy.equals("className")) {
return By.className(locateValue);
} else if (locateBy.equals("xPath")){
return By.xpath(locateValue);
} else {
return null;
}
}
}
写回答
1回答
-
Mushishi
2020-03-14
你好,可以得。但是后期如果你做并行运行得时候会有问题,单机 单独运行没问题。
012020-03-14
相似问题