錯誤:我試圖從Excel工作表中的數據以及這些測試數據傳遞到登錄和密碼字段,但我收到以下錯誤
FAILED: cptoadsLogin org.testng.TestNGException: The data provider is trying to pass 2 parameters but the method com.toads.Script.LoginDemo#cptoadsLogin takes 0 at org.testng.internal.Invoker.injectParameters(Invoker.java:1225) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1118) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) at org.testng.TestRunner.privateRun(TestRunner.java:774) at org.testng.TestRunner.run(TestRunner.java:624) at org.testng.SuiteRunner.runTest(SuiteRunner.java:359) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) at org.testng.SuiteRunner.run(SuiteRunner.java:261) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215) at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) at org.testng.TestNG.run(TestNG.java:1048) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Page對象:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
public class ToadsLogin {
@FindBy(how=How.XPATH,using="//input[@id='Username']")
WebElement username;
@FindBy(how=How.XPATH,using="//input[@id='Password']")
WebElement password;
@FindBy(how=How.XPATH,using="//button")
WebElement loginbtn;
public ToadsLogin(WebDriver driver)
{
PageFactory.initElements(driver, this);
}
public void unpwd(String un,String pwd)
{
username.sendKeys("un");
password.sendKeys("pwd");
}
public void clikonLogin()
{
loginbtn.click();
}
}
TestNG腳本:
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.toads.PoM.ToadsLogin;
import com.toads.lib.ExcelDataConfig;
public class LoginDemo extends SuperTestNG {
@Test(dataProvider="toadsLogin")
public void cptoadsLogin() throws Exception
{
ToadsLogin tlogin=new ToadsLogin(driver);
tlogin.unpwd("un", "pwd");
tlogin.clikonLogin();
Thread.sleep(5000);
driver.close();
}
@DataProvider(name="toadsLogin")
public Object[][] cpToadsLogin()
{
ExcelDataConfig config=new ExcelDataConfig("D:\\login.xlsx");
int rows=config.getRowCount(0);
Object[][] data1= new Object[rows][2];
for(int i=0;i<rows;i++)
{
data1[i][0]=config.getData(0, i, 0);
data1[i][1]=config.getData(0, i, 1);
}
return data1;
}
}
謝謝....但其也沒有工作,它將用戶名作爲un和密碼作爲pwd.it是nt從excel表格獲取數據 –
@RakeshKumar因爲這是你放在那裏的'tlogin.unpwd(「un」,「pwd」);'如果你魔杖需要改變它不同的值。 – Guy
這就是我不知道我到底需要更改腳本以從excel.its中提取數據的工作正常,但我不使用POM,但使用了POM,我正面臨數據驅動測試的這個問題 –