如何在Selenium中处理多用户登录

时间:2017-03-15 11:05:48

标签: selenium

我有一个网站,其中一个用户登录并提交一些内容然后移动到"用户二"这是一个seprarate用户名/密码然后到"第三"最后到了第四个"。所以我必须创建一个脚本,如果第一个用户完成提交,那么脚本应该以用户2登录,然后用户3登录,以便他们也可以提交。

我很困惑如何创建脚本,以便可以进行多用户登录。此外,我将使用POM(页面对象模型)来创建脚本。

感谢。

2 个答案:

答案 0 :(得分:0)

尝试这种方式: 使用所有用户ID和密码创建2D阵列列表,然后在两个循环内添加您的过程命令 1.登录 提交一些东西 3.最后命令注销该用户。

示例:

String arr[][]= { {"user1@abc.com","user2@abc.com"} , {"password1","password2"} }

for(i=0; i<2 ; i++){
 for(j=0; j<1 ; j++){
// Your logic here for login, submitting and logout
}
}

答案 1 :(得分:0)

尝试多个用户的2D数组列表的电子邮件ID和密码,请尝试以下操作:

1。使用webdriver输入URL

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.test.com/");

2。声明数组。

  

String arr [] [] = {   {“ user1@test.com”,“ user2@test.com”},   {“ Test @ 123”,“ Test @ 123”}};

3。然后编写代码并注销当前登录用户:-

for(int i=0; i<arr.length-1 ; i++){

for(int j=0;j<arr.length;j++) { 

//Find Login button     
driver.findElement(By.xpath("xpath")).click();

driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(arr[i][j]);

driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(arr[i+1][j]);

//Click on Submit button
driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();

//Add your code
//Log out
driver.findElement(By.xpath("xpath")).click();           
        }    
    }

这个问题的另一个逻辑是, 我们只能使用一个for循环

  

字符串arr [] [] = {{“ user1@test.com”,“ Test @ 123”},   {“ user2@test.com”,“ Test @ 123”}};

for(int i=0;i<arr.length;i++)
{


driver.findElement(By.xpath("xpath")).click();       

driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys(arr[i][0]);

driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(arr[i][1]);

//Click on Submit button
driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();

//Add your code        
//Log out
driver.findElement(By.xpath("xpath")).click(); 
}   
相关问题