java - 如何一次使用 5 个登录来执行登录功能的负载测试
问题描述
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 个登录凭据运行应用程序,如果可能的话,还需要使用不同的浏览器。请建议我需要做的修改。
解决方案
您可以尝试实现一个静态方法来获取用户名/密码(这只是pseudo code
)
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();
}
}
推荐阅读
- javascript - Vue.js 将事件绑定到 SVG 图像元素
- javascript - 更改最外面的 svg 大小,但保留该 svg 内所有内容的大小
- python - 删除熊猫中的列的最佳方法是什么
- linux - 在 linux compile 中错过 asm/types.h
- date - CakePHP 3 日期格式问题
- javascript - 如何在Javascript中旋转图像?
- amazon-web-services - AWS lambda Step Functions 活动和 RDS
- java - 如何从 Java 中的后台服务发送 POST 请求?
- java - Install4J 注册自定义 URI Mac
- java - Maven 项目的资源文件夹丢失其资源定义