gpt4 book ai didi

java - 我如何使用 testng 将多个测试数据发送到以下内容

转载 作者:行者123 更新时间:2023-12-02 05:34:37 24 4
gpt4 key购买 nike

请建议我如何在 3 个浏览器中向此字段发送 3 个用户

driver.findElement(By.id(PropertiesConfiguration.getMyProperty("PinTextfield"))).sendKeys(PropertiesConfiguration.getMyProperty("user")); 

// main class

public class TestHRWW {`main class`

protected WebDriver driver;
@Parameters("browser")`parameter for browser initialization`
@BeforeClass
public void setup(String browser) {
if (browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("iexplorer")) {
System.setProperty("webdriver.ie.driver","Drivers\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver","Drivers\\chromedriver.exe");
driver = new ChromeDriver();
}
else {
throw new IllegalArgumentException("The Browser Type is Undefined");
}
driver.manage().window().maximize();
}

@BeforeMethod
public void open() {
driver.get("http://www.myhrasiapacific.com/");
}
@AfterClass
public void teardown() {
try {
driver.quit();
} catch (Exception e) {
driver = null;
}

}

// sub class
public class Login extends TestHRWW {`sub class`
String x;
static Logger logger = Logger.getLogger(Login.class.getName());
@Test
public void ClickLogon(WebDriver driver) throws InterruptedException, IOException {
driver.findElement(`enter code here`
By.id(PropertiesConfiguration.getMyProperty("logonbutton")))
.click();
Thread.sleep(2000);
// here i need to sent 3 differt users credentials
driver.findElement(
By.id(PropertiesConfiguration.getMyProperty("PinTextfield")))
.sendKeys(PropertiesConfiguration.getMyProperty("user"));
Thread.sleep(2000);
driver.findElement(
By.id(PropertiesConfiguration
.getMyProperty("passwordTextfield"))).sendKeys(
PropertiesConfiguration.getMyProperty("password"));
Thread.sleep(2000);
driver.findElement(
By.id(PropertiesConfiguration.getMyProperty("loginbutton")))
.click();
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

}

}

最佳答案

您应使用 TestNG @DataProvider 传递用户名和密码

您的登录方法将类似于

@Test(dataProvider="dataForLogin")
public void ClickLogon(String userName,String password) {
}

@DataProvider(name="dataForLogin")
public static Object[][] prepareDataForLogin(){
// preparation of login data
}

关于java - 我如何使用 testng 将多个测试数据发送到以下内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25136870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com