首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用JAVA验证使用Selenium的管理员仪表板和客户仪表板

问如何用JAVA验证使用Selenium的管理员仪表板和客户仪表板
EN

Stack Overflow用户
提问于 2020-04-03 16:31:14
回答 1查看 182关注 0票数 1

如何在JAVA中验证使用Selenium的管理员仪表板和客户仪表板:

管理仪表板-例如:在管理(仪表板、客户和管理)客户仪表板中有3个模块-例如:有2个模块,如(仪表板和客户)

在上述方案中,如果我登录到customer并验证Dashboard和Customer模块是否可用。如果我执行脚本-它是验证两个模块,但如何验证管理模块也在客户登录-这是一个错误的权利。如果有人知道如何在java中验证selenium使用,请让我知道。

EN

回答 1

Stack Overflow用户

发布于 2020-05-05 21:02:29

首先,检查已登录的用户角色

代码语言:javascript
复制
// 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)终止

请检查并让我知道它的工作为您。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61007896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档