如何在JAVA中验证使用Selenium的管理员仪表板和客户仪表板:
管理仪表板-例如:在管理(仪表板、客户和管理)客户仪表板中有3个模块-例如:有2个模块,如(仪表板和客户)
在上述方案中,如果我登录到customer并验证Dashboard和Customer模块是否可用。如果我执行脚本-它是验证两个模块,但如何验证管理模块也在客户登录-这是一个错误的权利。如果有人知道如何在java中验证selenium使用,请让我知道。
发布于 2020-05-05 21:02:29
首先,检查已登录的用户角色
// Test for Customer Role
if (role == Customer) {
// Get all the modules available to current logged-in role i.e. Customer
List <WebElement> module = driver.findElements(By.id("xyz"));
// check the how many modules present for customer
if (module.size() == 2) {
for (WebElement mod: module) {
// if the count is 2 then will check if present modules have Admin one if yes, then will fail the test
if (mod.getText() == "Admin") {
System.out.println("Failed");
break;
} else {
System.out.println("Pass");
}
}
}
// if 3 modules are present for Customer, then will directly fail the test
else if(module.size() == 3) {
System.out.println("Failed");
Break;
}
}
// Now check for Admin role
else {
// Again will get the modules present for the Admin role
List <WebElement> module1 = driver.findElements(By.id("xyz"));
// check the module size if its 2 then we directly fail the test
if (module1.size() == 2) {
System.out.println("Failed");
Break;
}
// if module size is 3
else {
for (WebElement mod1: module1) {
// if the count is 3 then will check if all the 3 correct modules are present.
if (mod1.getText() == "Admin") {
continue;
} else if (mod1.getText() == "Customer") {
continue;
} else if ( mod1.getText() == "Dashboard") {
continue;
} else {
break;
}
}
}
}
//Test for Customer Role
if (role == Customer) {
// Get all the modules available to current logged-in role i.e. Customer
List <WebElement> module = driver.findElements(By.id("xyz"));
// check the how many modules present for customer
if (module.size() == 2) {
for (WebElement mod: module) {
//if the count is 2 then will check if present modules have Admin one if yes , then will fail the test
if (mod.getText() == "Admin") {
System.out.println("Failed");
Break;
} else {
System.out.println("Pass");
}
}
}
// if 3 modules are present for Customer, then will directly fail the test
else if (module.size() == 3) {
System.out.println("Failed");
Break;
}
}
// Now check for Admin role
else {
// Again will get the modules present for the Admin role
List <WebElement> module1 = driver.findElements(By.id("xyz"));
// check the module size if its 2 then we directly fail the test
if (module1.size() == 2){
System.out.println("Failed");
Break;
}
// if module size is 3
else {
for (WebElement mod1: module1) {
// if the count is 3 then will check if all the 3 correct modules are present.
if (mod1.getText() == "Admin") {
continue;
} else if (mod1.getText() == "Customer") {
continue;
} else if (mod1.getText() == "Dashboard") {
continue;
} else {
break;
}
}
}
}例如,目前,我们以客户角色登录,当我们运行脚本时,它有所有3个模块可用(根据您的要求,这是一个否定的场景)-测试将在(Module.size()==3)终止
请检查并让我知道它的工作为您。
https://stackoverflow.com/questions/61007896
复制相似问题