我有一个非常简单的测试场景设置,基本上打开浏览器并做一些导航和它的所有工作的罚款。当我分开的一些步骤进行到common_steps文件,(4倍)浏览器的多个实例是打开这又未能通过测试,因为元素无法被发现。
当我复制的共同步骤回原始文件,测试运行良好。我有点困惑,因为我不明白它是如何打开多个浏览器时,有在特征文件中没有额外的步骤或行告诉它这样做。
这是我如何走近它的例子。我知道代码是有点乱糟糟的,它需要的东西就像一个全球性的等待等,但之后我解决这个问题,将完成,这是一项正在进行的工作。
脚本
Scenario Outline: Navigate through Chrome
Given I opened the home page of "<homeUrl>"
Then navigated to my favourite site of "<myFavUrl>"
Then navigated to the Dojo page
When the full catalog was displayed
And the performance option was selected
Examples:
|homeUrl |myFavUrl |
|https:\\www.google.co.uk |https://www.ministryoftesting.com/ |
常量文件。
public class Constant {
public WebDriver driver;
public Constant() {
System.setProperty("webdriver.chrome.driver", "path_to\\chromedriver.exe");
driver = new ChromeDriver();
}
public WebDriver setChromeDriver() {
if(driver == null) {
driver = new ChromeDriver();
driver.manage().window().maximize();
return driver;
}else
return driver;
}
}
常见的步骤文件。
public class CommonSteps extends Constant {
@Given("^I opened the home page of \"([^\"]*)\"$")
public void navigateToHomePage(String url) throws Throwable{
driver.get(url);
driver.manage().window().maximize();
}
@Then("^navigated to my favourite site of \"([^\"]*)\"$")
public void navigateToFavourite(String myFavSite) throws Throwable{
driver.get(myFavSite);
}
//To be used in a separate scenario
@Given("^I opened the home page of Ministry Of Testing$")
public void quickLinkToMot() throws Throwable{
driver.get("https://www.ministryoftesting.com/");
driver.manage().window().maximize();
}
}
具体步骤文件
@Then("^navigated to the Dojo page$")
public void navigateToDojo() throws Throwable{
WebDriverWait wait = new WebDriverWait(driver, 5000);
WebElement djLinkParent = driver.findElement(By.id("navbar-collapse"));
WebElement djLink = wait.until(ExpectedConditions.elementToBeClickable(djLinkParent.findElement(By.linkText("Dojo"))));
djLink.click();
}
@When("^the full catalog was displayed$")
public void displayFullCatalog() throws Throwable{
WebDriverWait wait = new WebDriverWait(driver, 5000);
WebElement fullCatBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("[class='btn btn-xl btn-home']")));
fullCatBtn.click();
}
@And("^the performance option was selected$")
public void selectPerformance() throws Throwable{
WebDriverWait wait = new WebDriverWait(driver, 5000);
WebElement pBtnParent = driver.findElement(By.cssSelector("[class='cat cat2']"));
WebElement perfLink = wait.until(ExpectedConditions.elementToBeClickable(pBtnParent.findElement(By.xpath("//a[@href='/dojo/lessons?topic=performance']"))));
perfLink.click();
}
项目的建设是不正确的。结构可以改变,但是当你需要使用BDD黄瓜那么这意味着你要它在你的项目的概念。然后,你需要按照国家的最先进的技术来做到这一点。请看看下面。
解:
我认为,解决问题的方法是写here。
它会告诉你如何在你的项目中的架构,因为我相信你的架构是错误的。
我认为这是你在找什么。