java - 如何一次使用 5 个登录来执行登录功能的负载测试

标签 java selenium load-testing

public class Login {

public WebDriver driver ;

@Test(invocationCount = 20, threadPoolSize = 5)
public void GmailLogin() throws InterruptedException {
WebDriver driver = LoadTest.getInstance().getDriver();  
driver.get("https://tst-oec-ebooking.azurewebsites.net/");    
driver.findElement(By.xpath("//html/body/div/div/div[2]/div/form/div/input")).sendKeys("mad@dayrep.com");
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"Password\"]")).sendKeys("Pass@123");
driver.findElement(By.xpath("//*[@id=\"login_submit\"]")).click();
Thread.sleep(1500);
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);

}

@BeforeMethod
public void setup(){
  System.setProperty("webdriver.gecko.driver", "D:\\CIPL0564\\D Drive\\Software\\geckodriver-v0.20.1-win64\\geckodriver.exe");

}

@AfterMethod
public void tearDown(){
LoadTest.getInstance().removeDriver();
}
}

通过执行上述代码,应用程序使用相同的登录名运行 20 次。但是我需要每次使用 5 个登录凭据运行应用程序,如果可能的话还可以使用不同的浏览器。请建议我需要进行的修改。

最佳答案

您可以尝试实现静态方法来获取用户名/密码(这只是伪代码)

public class CredentialHelper {
private static int counter = 0;
private static List<MyGmailCredential> myGmailCredentials = [5 credentials];
public static synchronized MyGmailCredential getCredential() {
    MyGmailCredential currentCred = CredentialHelper.myGmailCredentials[counter%5];
    CredentialHelper.counter++;
    return currenCred;
}
}

在类里面使用

public class Login {

public WebDriver driver ;

@Test(invocationCount = 20, threadPoolSize = 5)
public void GmailLogin() throws InterruptedException {
WebDriver driver = LoadTest.getInstance().getDriver();  
driver.get("https://tst-oec-ebooking.azurewebsites.net/");    
MyGmailCredential myGmailCredential = CredentialHelper.getCredential();
driver.findElement(By.xpath("//html/body/div/div/div[2]/div/form/div/input")).sendKeys(myGmailCredential.getUserName());
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"Password\"]")).sendKeys(myGmailCredential.getPassword());
driver.findElement(By.xpath("//*[@id=\"login_submit\"]")).click();
Thread.sleep(1500);
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);

}

@BeforeMethod
public void setup(){
  System.setProperty("webdriver.gecko.driver", "D:\\CIPL0564\\D Drive\\Software\\geckodriver-v0.20.1-win64\\geckodriver.exe");

}

@AfterMethod
public void tearDown(){
LoadTest.getInstance().removeDriver();
}
}

关于java - 如何一次使用 5 个登录来执行登录功能的负载测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51076526/

相关文章:

java - 在 RecyclerView Adapter 中使用 onActivityResult

java - 如何在java中键盘输入后更改图像?

asp.net - 如何对 ASP.NET 应用程序进行负载测试?

java - 如何忽略InputStream中的字符?

python - 如何格式化 Beautiful Soup 和 Selenium 的输出?

java - 带有 div.span 的复选框未点击

javascript - 更改时间 webdriver selenium

azure - 尝试使用 Selenium Chrome 驱动程序在 Azure 中运行 VS 负载测试并收到错误

http - 如何缓慢地提供 HTTP?

javascript - 当 AJAX GET 请求发送到 Servlet 时,Java Servlet 总是返回调用页面的 HTML 代码