我已经创建了一个带有功能文件,glueclass和testRunner类的示例黄瓜测试。与正常情况下运行TestRunner类的情况一样,我看到结果被设置为可以运行,但浏览器未启动以下屏幕截图。
但是我可以从功能文件中启动它。 我不明白为什么会这样。 请在下面的项目结构中查找
功能文件:
package loginpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import junit.framework.Assert;
public class Logintest {
WebDriver driver;
@Given("^User is on Home Page$")
public void user_is_on_Home_Page() throws Throwable{
System.out.println("Value in portal :");
System.setProperty("webdriver.chrome.driver", "E:\\FireKWDemo\\ext\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://www.google.com");
}
@When("^User enters \"([^\"]*)\" and Password$")
public void user_enters_UserName_and_Password(String q) throws Throwable {
driver.findElement(By.name("q")).sendKeys(q);
driver.findElement(By.name("btnK")).click();
}
@Then("^Message displayed Login Successfully$")
public void message_displayed_Login_Successfully() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("Test Successful");
driver.close();
}
}
胶水类:
school
答案 0 :(得分:0)
您缺少chrome需要的一些东西。首先,您需要告诉Selenium在哪里可以找到您先前下载并安装的chromedriver.exe。这是我在运行的一个系统上所拥有的。试试看,让我们知道是否可以解决。
System.setProperty("webdriver.chrome.driver", "C:\\User\you\\drivers\\ChromeDriver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("--disable-infobars");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
prefs.put("excludeSwitches", "enable-automation");
options.setExperimentalOption("prefs", prefs);
capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("version", "latest");
capabilities.setCapability("browserName", "chrome");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
try {
driver = new ChromeDriver(options);
driver.manage().deleteAllCookies();
} catch(Exception e) {
System.out.println("**>uh-oh " + e.getMessage());
}
答案 1 :(得分:0)
测试运行器类中的步骤定义路径在哪里?在给定的屏幕截图中丢失了。
在测试运行器类中使用以下信息:
features = "/Users/NaveenKhunteta/Documents/workspace/CucumberPOM/src/main/java/com/qa/features/freecrm.feature", //the path of the feature files
glue={"com/qa/stepDefinitions"}, //the path of the step definition files
format= {"pretty","html:test-outout", "json:json_output/cucumber.json", "junit:junit_xml/cucumber.xml"}, //to generate different types of reporting
monochrome = true, //display the console output in a proper readable format
strict = true, //it will check if any step is not defined in step definition file
dryRun = false //to check the mapping is proper between feature file and step def file
)
答案 2 :(得分:0)
您为什么评论胶水选项的行?
删除注释注释选项,您应该添加标签以运行测试。也未提供。从场景的功能文件的 runner类中添加标签,然后进行检查。
答案 3 :(得分:0)
glue
选项应声明,否则应如何找到功能文件的代码。
@RunWith(Cucumber.class)
@CucumberOptions(features="src/Feature",glue={"Stepdefination"},
plugin = { "pretty", "json:target/cucumber-reports/cucumber.json" },
monochrome = true
)