浏览器在使用Cucumber + Java + Selenium时使用两次

时间:2018-08-15 16:56:38

标签: selenium cucumber-java

我有2个步骤定义文件/ 2个特征文件,这些文件由运行程序文件运行。当我运行脚本时,每次都会打开2个浏览器。不知道我在做什么错。我的跑步者档案如下

package KohlsLoginTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "html:target/cucumber-html-report", 
                        "pretty:target/cucumber-pretty.txt",
                        "junit:target/cucumber-results.xml" },
             features = { "./src/test/resources/Features" },
             tags = { "@SmokeTest" }
            )

 public class kohlsLoginRunner {

 }

我的步骤def文件如下,我有一个@before和@after钩子,抱怨是关于@before钩子。我不知道该怎么解决。

 public class kohlsLoginTest {  
 WebDriver driver = new ChromeDriver();

 @Before 
     public void before() throws InterruptedException {
     System.setProperty("webdriver.chrome.driver", 
            "C:\\Software\\Drivers\\chromedriver.exe");
     driver.manage().deleteAllCookies();

    //Navigate to the sign in screen
    driver.navigate().to("https://www.kohls.com");
    Thread.sleep(4000);

    WebElement account = driver.findElement(By.xpath("//* 
                  [@id=\"utility-nav\"]/ul/li[1]/div[1]/a"));
     account.click();

    WebElement signin = driver.findElement(By.xpath("//* 
      [@id=\"pb_signin\"]/div"));
    signin.click();
     }

我在Eclipse中的文件结构如下:

file structure in eclipse

0 个答案:

没有答案