I am trying to write test cases with the different Users with their permissions. I have a situation where there are two users
- Admin- with full permissions
- 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.
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
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=""> 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=""> 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&start_date=01-01-2020" rel="tooltip">
<i aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" style=""> 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&start_date=01-05-2022" rel="tooltip">
<i aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" style=""> 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=""> 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=""> 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=""> 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&start_date=01-05-2022" rel="tooltip">
<i aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" style=""> 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.");
}
}