public class Tester implements Runnable {
public Tester() {
// Init WebDriver
FirefoxProfile firefoxProfile = new FirefoxProfile();
WebDriver browser1 = new FirefoxDriver(firefoxProfile);
WebDriver browser2 = new FirefoxDriver(firefoxProfile);
}
public static void main(String[] args) {
Runnable tester = new Tester();
Thread worker1 = new Thread(tester);
Thread worker2 = new Thread(tester);
worker1.start();
worker2.start();
}
public void run(WebDriver driver) {
login(driver, "username", "password", "http://someurl.com/login");
}
}
我试图将驱动程序参数传递给run()方法,但它是否需要参数?我在哪里通过browser1和浏览器2?
我的最终目标是让多个firefox浏览器实例运行相同的测试。
答案 0 :(得分:1)
run()
方法没有任何参数。
你可以在你的线程实现上使用'setters'来做。有了这个,您的代码应该看起来像 -
Tester tester = new Tester();
tester.setBrowser1(new FirefoxDriver( ....
tester.setBrowser2(new FirefoxDriver( ....
Thread worker2 = new Thread(tester);
您的测试人员将使用browser1和browser2作为实例变量。或者您也可以通过Tester的构造函数设置browser1和browser2。
答案 1 :(得分:0)
添加一个构造函数,它将浏览器作为参数。将引用存储在私有字段中,您可以在run方法中使用Browser:
public class Tester implements Runnable {
private WebDriver browser;
public Tester(WebDriver browser) {
this.browser = browser;
}
public static void main(String[] args) {
Thread worker1 = new Thread(new Tester(new FirefoxDriver(firefoxProfile)));
Thread worker2 = new Thread(new Tester(new FirefoxDriver(firefoxProfile)));
worker1.start();
worker2.start();
}
public void run() {
login(browser, "username", "password", "http://someurl.com/login");
}
}