我是黄瓜框架的新手,我使用testNG框架研究了selenium webdriver。我必须启动黄瓜框架,我已经安装了黄瓜插件来eclipse但不知道如何开始编写代码。
黄瓜和黄瓜-jvm有什么区别,哪个最好?
有人可以帮助我吗?
提前致谢。
答案 0 :(得分:2)
您可以在黄瓜主站Cucumber Documentation上找到有关您应该为项目使用的依赖项的大量信息。{/ p>
黄瓜基地是红宝石
Cucumber-JVM是Java
Feature: Calculator should work accourding to standard calculator devices
Scenario: addition
Given a calculator I just turned on
When I add 4 and 5
Then the result is 9
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
monochrome = false,
plugin = {"pretty","json:target/cucumber.json"} ,
features = "src/test/resources/cucumber",
tags = "~@ignore"
)
public class RunCukesTest {
}
这是您开始使用Cucumber所需的基础(github上有一个开始示例)
现在是Selenium的问题
import java.util.concurrent.TimeUnit;
import cucumber.api.java.en.*;
import org.eclipse.jetty.util.thread.Timeout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class NavigationSteps {
WebDriver _driver;
@Given("^i am at \"([^\"]*)\"$")
public void i_am_at_home(String arg1) throws Throwable {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
_driver = new ChromeDriver();
_driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
_driver.get(arg1);
Thread.sleep(500);
}
@When("^i click on \"([^\"]*)\"$")
public void i_click_on(String arg1) throws Throwable {
_driver.findElement(By.linkText(arg1)).click();
Thread.sleep(500);
}
@Then("^i expect the title to be \"(.*?)\"\"(.*?)\"$")
public void i_expect_the_title_to_be(String arg1, String arg2) throws Throwable {
String result = (arg1 + " | " + arg2);
Thread.sleep(200);
assertEquals("Title should be",result,_driver.getTitle());
tearDown();
}
@Then("^Header should contain \"(.*?)\"$")
public void header_should_contain(String arg1) throws Throwable {
Thread.sleep(200);
assertEquals("Title should be", arg1, _driver.findElement(By.xpath(".//*[@id='main']/div[1]/div/h1")).getText());
tearDown();
}
@After
public void tearDown() throws InterruptedException
{
_driver.quit();
}
}
编辑 - 以更好的格式回答问题
Given a calculator I just turned on
results into
@Given ("^a calculator I just turned on$")
public void iCanCallThisAnythingIWant(){
#do something
}