How to use a already opened firefox for testing in Selenium

前端 未结 6 783
不思量自难忘°
不思量自难忘° 2020-12-05 15:49

This declaration

WebDriver driver = new FirefoxDriver();

always opens a new instance window of Firefox. It doesn\'t use the already opened

6条回答
  •  臣服心动
    2020-12-05 16:26

    You should instantiate your webdriver only once, when making a test and then pass it as argument for the other classes in constructors. Something like this:

    public class Test {
    
    WebDriver driver = new FirefoxDriver();
    @Test
    public void testHomePage() {
        HomePage hp = new HomePage(driver);
        //code here }
    }
    
    
    public class HomePage{
    private static WebDriver driver;
    
    public HomePage(WebDriver driver) {
        this.driver = driver;}
    }
    

提交回复
热议问题