每当新场景开始执行时,浏览器就会打开

时间:2019-11-11 06:01:43

标签: cucumber-java

每当从我的功能文件开始执行新方案时,就会启动新的浏览器。我希望浏览器只能在执行第一个方案时启动一次,而在其余方案中,不应打​​开新的浏览器。

我已将我的浏览器打开代码写入@Before类下的Hooks注释中。

@Before(order=1)
public void initialization(Scenario scenario){
log.debug("This is testing for log");
System.setProperty("webdriver.chrome.driver", 
System.getProperty("user.dir")+"\\src\\test\\java\\drivers\\chromedriver.exe");
driver = new ChromeDriver();

}

My Feature file is as below:

Feature: SignUp Functionality

   @tag1
   Scenario: Verify the SignUp functionality
   Given User is on Home Page
   When User click on the SignUp link
   And Enters signup details
   Then the user should be signed up successfully
   And success message should display

   @tag2
   Scenario: Verify the Login functionality
   Given: User is on the Login page
   When: User enters valid credentials and clicks on the login button
   Then: User should log in successfully and dashboard should display.`

1 个答案:

答案 0 :(得分:0)

作为最佳实践,您应该避免使用它,但是作为答案,有几种方法可以做到。

首先,您可以使用@BeforeClass@AfterClass批注来调用和杀死@Before@After旁的浏览器,然后在之前和之后的批注中获取当前的浏览器实例。

您也可以选中此stackoverflow answer