我有一个字符串数组,对于数组中的每个字符串,我想验证它是否显示在网页上然后打开该链接。我无法弄清楚如何使我的测试成为参数化测试。我非常感谢帮助,谢谢
package testCases;
import junitparams.JUnitParamsRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.PageFactory;
import pageObjects.HomePage;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
/**
* Created by blah on 12/17/2015.
*/
@RunWith(value = JUnitParamsRunner.class)
public class ******
{
// Create Page Objects
HomePage hp;
WebDriver driver;
ArrayList<String> tableData = new ArrayList<String>();
// @Test
// @Parameters({something})
//
// public void test_add(String asdas) {
// hp.checkLink(asdas);
// }
@Before
public void setup()
{
// Configure Chrome Options
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Initialize Page Objects
hp = PageFactory.initElements(driver, HomePage.class);
}
// Pre Reqs
@Test
public void P1()
{
driver.get("the website I go to");
tableData= hp.readSystemTableData();
hp.checkLinks(tableData);
// hp.getTitle();
tearDown();
}
@After
public void tearDown()
{
driver.quit();
}
}
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at junitparams.internal.InvokeParameterisedMethod.evaluate(InvokeParameterisedMethod.java:211)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at junitparams.internal.ParameterisedTestMethodRunner.runMethodInvoker(ParameterisedTestMethodRunner.java:47)
at junitparams.internal.ParameterisedTestMethodRunner.runTestMethod(ParameterisedTestMethodRunner.java:40)
at junitparams.internal.ParameterisedTestClassRunner.runParameterisedTest(ParameterisedTestClassRunner.java:147)
at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:414)
at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:385)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
答案 0 :(得分:0)
您可以按如下方式进行参数化测试用例:
@RunWith(JUnitParamsRunner.class)
public class ****
{
// ..... code .....
public static final Object[] getTableData()
{
return new Object[][] {{data1},{data2},{data3}};
}
@Test
@Parameters(method = "getTableData")
public void p1(String tblData)
{
//.....code.....
hp.checkLinks(tblData);
//.....code.....
}
// .... code .....
}
试试这种方式。它可能会奏效。这是另一种做法。