Home > Blockchain >  How to write a test case for the icon which is not displayed on the page due to permissions
How to write a test case for the icon which is not displayed on the page due to permissions

Time:05-13

I am trying to write test cases with the different Users with their permissions. I have a situation where there are two users

  1. Admin- with full permissions
  2. Laydown User with limited access.

Now I want to write a testcase when Laydown User is Logged in and hes not able to see his budget Icon.

  1. Budget Icon is not present when he logs in (not hidden as well) so I dont understand how do I uniquely identify it ? I was planning to use IsDisplayed() method but how do I take the path if the icon itself is not present

  2. I though of taking path when Admin logs in but that obviously is not working as the Icon is not present when the Laydown logs in

Is there any way to assert and test this ?

Below is the HTML code when Admin logs in: (You should be able to see Budget here)

<nav id="mainnav-container" ng-if="Engine.hideMainNav != true" >
    <div >
        <a href="/app_dev.php/" >
        </a>
    </div>
        <div >
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine" ui-sref-active="active" navigator-tooltip="Dashboard" type="button"  dashboard="" style="position:relative;" href="#!/" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Dashboard</span>
                             </a>
                     
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine.budget({start_date:'01-01-2020',end_date:'31-12-2020'})" ui-sref-active="active" navigator-tooltip="Budgets" type="button"  budgets="" style="position:relative;" href="#!/budget/" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Budgets</span>
                             </a>
                     
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine.activation({start_date:'01-01-2020',end_date:'31-12-2020'})" ui-sref-active="active" navigator-tooltip="Activations" type="button"  activations="" style="position:relative;" href="#!/activation/?end_date=31-12-2020&amp;start_date=01-01-2020" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Activations</span>
                             </a>
                     
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine.laydown({'start_date':'01-05-2022','end_date':'30-09-2022'})" ui-sref-active="active" navigator-tooltip="Activities" type="button"  activities="" style="position:relative;" href="#!/activity/?end_date=30-09-2022&amp;start_date=01-05-2022" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Activities</span>
                             </a>
                     
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine.crmLite" ui-sref-active="active" navigator-tooltip="Manage Users" type="button"  manage="" users="" style="position:relative;" href="#!/manage-users/" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Manage Users</span>
                             </a>
                     
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine.reporting" ui-sref-active="active" ng-init="Engine.sidebarloop6 = true" ng-click="Engine.sidebarloop6 = !Engine.sidebarloop6" navigator-tooltip="Reports" type="button"  reports="" style="position:relative;" href="#!/reporting-suite/" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Reports</span>
                             </a>
                     
        
    </div>
    
    </nav>

And this is the HTML when Laydown logs-in : He can see only Dashboard and activities

<nav id="mainnav-container" ng-if="Engine.hideMainNav != true" >
    <div >
        <a href="/app_dev.php/" >
        </a>
    </div>
        <div >
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine" ui-sref-active="active" navigator-tooltip="Dashboard" type="button"  dashboard="" style="position:relative;" href="#!/" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Dashboard</span>
                             </a>
                     
                                            
                                            
                                                            
            <!-- ui-sref-opts="{reload: true}" -->
            <a ui-sref="base.engine.laydown({'start_date':'01-05-2022','end_date':'30-09-2022'})" ui-sref-active="active" navigator-tooltip="Activities" type="button"  activities="" style="position:relative;" href="#!/activity/?end_date=30-09-2022&amp;start_date=01-05-2022" rel="tooltip">
                <i  aria-hidden="true"></i> 
                <span ng-show="Engine.offsetMainnav"  style="">&nbsp;Activities</span>
                             </a>
                     
                                            
                                            
        
    </div>
    
    </nav>

CodePudding user response:

You can write a method to search for an element and return true if it is available else return false.

public static boolean isElementDisplayed() {
    try {
        driver.findElement(By.xpath("//span[contains(text(),'Budgets')]"));
        return true;
    } catch (org.openqa.selenium.NoSuchElementException e) {
        return false;
    }
}

In your tests,

@Test
public void laydownUserCheck() {
    if (isElementDisplayed()) {
        Assert.fail("Displaying the budget icon for laydown user.");
    }
}

@Test
public void adminUserCheck() {
    if (!isElementDisplayed()) {
        Assert.fail("Not displaying the budget icon for admin user.");
    }
}
  • Related