如何在多个场景中在黄瓜中运行特定场景?
特征文件
Feature: Test Test Smoke scenario
Scenario: Test login with valid credentials
Given open firefox and start application
Run Code Online (Sandbox Code Playgroud)
jhbhhjhj 当我点击登录并输入有效的“kumar.rakesh@yopmail.com”和有效的“admin@123”然后点击登录,用户应该能够成功登录
Scenario: Test shop for cart
Given Click on shop for carts
And select plates
When Click on Add to cart
Then product should be added in the cart successfully
And verify the product
Scenario: Test login with valid credentials1
Given open firefox and start application
When I click on Login
And enter valid "kumar.rakesh@yopmail.com" and valid "admin@123"
Then Click …
Run Code Online (Sandbox Code Playgroud) 错误:
失败:cptoadsLogin org.testng.TestNGException:数据提供程序试图传递2个参数,但是com.toads.Script.LoginDemo#cptoadsLogin方法在org.testng.internal.Invoker.injectParameters(Invoker.java:1225)处采用0 org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)上的org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1118)org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)在org.testng的org.testng.SuiteRunner.runTest(SuiteRunner.java:359)的org.testng.TestRunner.run(TestRunner.java:624)的org.testng.TestRunner.privateRun(TestRunner.java:774)处。 org.testng.SuiteRunner.privateRun(SuiteRunner。)上的SuiteRunner.runSequentially(SuiteRunner.java:354)org.testng.SuiteRunner.run(SuiteRunner.java:261)处的org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)处的org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)处的java:312) org.testng.TestNG.run(TestNG.java:1048)在org.testng.TestNG.runSuitesLocally(TestNG.java:1140)在org.testng.TestNG.run(TestNG.java:1048)在org.testng.remote org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)的org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)的.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)在org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)在org.testng.TestNG.runSuitesLocally(TestNG.java:1140)在org.testng.TestNG.run(TestNG)的SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) .java:1048),位于org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132),位于org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236),位于org.testng.remote.RemoteTestNG.main( RemoteTestNG.java:81)在org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)在org.testng.TestNG.runSuitesLocally(TestNG.java:1140)在org.testng.TestNG.run(TestNG)的SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) .java:1048),位于org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132),位于org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236),位于org.testng.remote.RemoteTestNG.main( RemoteTestNG.java:81)org.testng.remote.RemoteTestNG.main上的initAndRun(RemoteTestNG.java:236)(RemoteTestNG.java:81)org.testng.remote.RemoteTestNG.main上的initAndRun(RemoteTestNG.java:236)(RemoteTestNG.java:81)
页面对象:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
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
{ …
Run Code Online (Sandbox Code Playgroud)