Selenium java Browser session reuse

前端 未结 3 944
囚心锁ツ
囚心锁ツ 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:30

    One of the simple way which i figured out recently is to make the webdriver as static under class and reuse the same webdriver in any other test case

    For example in testcase1:

    public class globallogin { 
        static WebDriver driver = new ChromeDriver(); 
    } 
    

    Now you can call the same webdriver in test case 2 as:

    public class skucategory {
    
        static globallogin login = new globallogin(); 
    
        public static void main(String[] args) { 
            login.driver.get(); 
        } 
    }
    

提交回复
热议问题