簡體   English   中英

如何一次使用5個登錄名執行登錄功能的負載測試

[英]How to perform load test of login functionality using 5 logins at a time

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();
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM