我正面临在Maven项目中与Cucumber合作的下一个问题。 这是因为我没有这样做的Runnable方法。 我一直在寻找有关的信息,但这对我来说很难。
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters.<init>(BlockJUnit4ClassRunnerWithParameters.java:27)
at org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory.createRunnerForTestWithParameters(BlockJUnit4ClassRunnerWithParametersFactory.java:16)
at org.junit.runners.Parameterized.createRunnersForParameters(Parameterized.java:313)
at org.junit.runners.Parameterized.<init>(Parameterized.java:248)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
这是我的Runner Cucumber Class:
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(features={"src/features/Login.feature"}
,format = {"pretty", "html:target/cucumber"}
,glue = {"cucumber.CucumberStepDefs"}
)
/*@Suite.SuiteClasses({
CucumberStepDefs.class,
})*/
public class CucumberRunnerTest {
}
这是我的Selenium / cucumber课程:
import cl.chipacorp.test.SolutAutomatedWebTest;
import cl.chipacorp.util.data.SetDatos;
import cl.chipacorp.util.report.Report;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.By;
import org.openqa.selenium.ie.InternetExplorerDriver;
import java.util.concurrent.TimeUnit;
//JAVA
@RunWith(value = Parameterized.class)
public class CucumberStepDefs extends CoopeuchAutomatedWebTest {
@Parameterized.Parameter(value = 0)
public String usuario;
@Parameterized.Parameter(value = 1)
public String pass;
@Parameterized.Parameters
public static Object[] data() {
return SetDatos.getInstance().getData(CucumberStepDefs.class);
}
@Given("^Ingresar a la URL de Branch en ambiente QA$")
public void Login() throws Exception {
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
baseUrl = "http://brs1coreqa-01.coopeuch1.cl/";
driver.get(baseUrl + "IBSBranchnet_COOPEUCH_Q5A/WebTeller.htm");
driver.switchTo ().defaultContent ();
driver.switchTo ().frame ("frmbody");
}
@When("^Se desplieguen los campos Username y Password, Ingresar las credenciales correspondientes$")
public void UsuarioPass () throws Exception {
driver.findElement(By.id("TxbTELLUSERID")).clear();
driver.findElement(By.id("TxbTELLUSERID")).sendKeys(usuario);
driver.findElement(By.id("TxbUSERPASSW")).clear();
driver.findElement(By.id("TxbUSERPASSW")).sendKeys(pass);
screenshot.take (this, driver, "LoginR C01");
driver.findElement(By.id("BtnSubmit")).click();
}
@Then("^Usuario accede a Branch con su correspondiente usuario$")
public void Logout () throws Exception {
driver.switchTo ().defaultContent ();
driver.switchTo ().frame ("frmwebteller");
driver.manage().window().maximize();
screenshot.take (this, driver, "LoginR C02");
driver.switchTo ().defaultContent ();
driver.switchTo ().frame ("frmbody").switchTo ().frame ("menu"); //main - suboption0001
driver.findElement(By.cssSelector("b")).click();
screenshot.take (this, driver, "LoginR C03");
driver.findElement(By.linkText("Log Off")).click();
screenshot.take (this, driver, "LoginR C04");
//REPORTE NO BORRAR.
Report.getInstance ().createReport (this, screenshot.getImages (),usuario);
driver.quit();
}
}
另一方面,这些是我的POM依赖项:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-ie-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-edge-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-opera-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${apache.poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${apache.poi.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>${appium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>${gherkin.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
我寻求帮助,但我是Cucumber的新人。 你能帮帮我吗?
答案 0 :(得分:0)
问题是你不再使用Cucumber
跑步者了。对于每组参数,Parameterized
运行器使用标准BlockJunit4ClassRunner
运行测试。因此,它通过查找您不再拥有的@Test
注释的方法来发现测试。
你想要做的是使用Parameterized
跑步者,但让它在内部使用Cucumber
跑步者。从JUnit 4.12开始,这是可能的:
@RunWith(Parameterized.class)
@UseParametersRunnerFactory(CucumberRunnerFactory.class)
public class CucumberStepDefs extends CoopeuchAutomatedWebTest {
public static class CucumberRunnerFactor
implements ParameterizedRunnerFactory {
public Runner createRunnerForTestWithParameters(
TestWithParameters test
) throws InitializationError {
try {
return Cucumber(test.getTestClass().getJavaClass());
} catch (IOException e) {
throw new InitializationError(e);
}
}
}
@Parameterized.Parameters
public static Object[] data() {
return SetDatos.getInstance().getData(CucumberStepDefs.class);
}
@Parameterized.Parameter(value = 0)
public String usuario;
...
}