我创建了三个文件.feature文件stepDefinition.java和testRunner.java。当我尝试运行testRunner类时,它会继续在控制台中显示建议,例如您可以使用以下代码片段实现缺少的步骤:功能文件中的步骤。具有讽刺意味的是,我已经在stepDefinition中实现了所有步骤。有人可以帮我吗?
login.feature
Feature: Amazon login feature
Scenario: Valid and invalid test cases
Given user already in login page
When user enters username
Then user enters password
Then user click login page
stepDefinitions.java
package stepDefinition;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class stepdefinitions {
WebDriver driver=new ChromeDriver();
@Given("^user already in login page$")
public void user_already_in_login_page() throws Exception {
System.setProperty("webdriver.chrome.driver","D:\\MuthuKumar\\Documents\\chromedriver.exe");
driver.get("https://www.amazon.in/");
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id("nav-link-accountList"))).click(driver.findElement(By.xpath("//span[text()='Sign in']"))).build().perform();
}
@When("^user enters username$")
public void user_enters_username() throws Exception {
driver.findElement(By.id("ap_email")).sendKeys("8526606990");
driver.findElement(By.id("continue")).click();
}
@Then("^user enters password$")
public void user_enters_password() throws Exception {
driver.findElement(By.id("ap_password")).sendKeys("sample");
}
@Then("^user click login page$")
public void user_click_login_page() throws Exception {
driver.findElement(By.id("signInSubmit")).click();
}
}
testRunners.java
package testRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\feature"},glue= {"C:\\Users\\Admin\\Desktop\\Cucumber2222\\src\\test\\java\\stepDefinition"})
public class testRunners {
}
控制台消息
You can implement missing steps with the snippets below:
@Given("^user already in login page$")
public void user_already_in_login_page() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^user enters username$")
public void user_enters_username() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user enters password$")
public void user_enters_password() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user click login page$")
public void user_click_login_page() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
答案 0 :(得分:1)
只需给出您的包装名称,而不是使用胶水。效果很好
testRunners.java
<?php
$hostdb = 'localhost';
$namedb = 'dbname';
$userdb = 'dbuser';
$passdb = 'password';
$charset = 'utf8';
if (isset($_POST['code'] )) {
// Connect and create the PDO object
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
];
$conn = new PDO("mysql:host=$hostdb;dbname=$namedb;charset=$charset", $userdb, $passdb, $options);
try{
$conn->beginTransaction();
$stmt = $conn->prepare('UPDATE `Table1`
SET `check` = -1
WHERE `code` = :code AND `message` = "Ready" ' );
$stmt->execute(['code'=>$code ]);
$conn->commit();
echo "Done";
}catch(PDOException $e){
//roll back the changes on errors
$conn->rollback();
echo $e->getMessage();
}
}
?>