Selenium java Browser session reuse

前端 未结 3 972
囚心锁ツ
囚心锁ツ 2021-01-20 23:08

My question is as follows: How can I reuse a browser session for tests that are in different java classes? I have the browser open like this:

public class OpenBr         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 23:46

    You should check with QMetry Automation framework it provides driver management through TestBase. You don't need to create driver instance, just configure in property or xml configuration file and use driver in any class using 'getDriver()' call.

    WebDriver driver = WebDriverTestBase.getDriver();

    It also has different design concepts like TestPage, TestStep, DataBean, Locator Repository, Data-Driven Testing Listeners and many more.

    In order to configure driver, you can set property driver.name outside the code with driver name like

    driver.name=firefoxDriver

    If you want to run on multiple browser in parallel you can provide driver in xml configuration file like:

    
    
        
            
            
                
            
        
        
            
            
                
            
        
    
    

    In above example, it will run all test in my.pkg parallel in two different browsers. You don't need to create or quite driver object in your code.

    It also has mechanism to retry if driver creation fail, which is quite useful when you are running test on cloud.

提交回复
热议问题