图标因权限不显示在页面上如何编写测试用例
How to write a test case for the icon which is not displayed on the page due to permissions
我正在尝试使用具有不同权限的不同用户编写测试用例。
我的情况是有两个用户
- 管理员 - 拥有完全权限
- 具有有限访问权限的 Laydown 用户。
现在我想写一个测试用例,当 Laydown 用户登录并且他看不到他的预算图标时。
他登录时 不存在 预算图标(也未隐藏)所以我不明白如何唯一标识它?我打算使用 IsDisplayed() 方法,但如果图标本身不存在,我该如何选择路径
我想在 Admin 登录时选择路径,但这显然不起作用,因为 Laydown 登录时图标不存在
有什么方法可以断言和测试这个吗?
下面是管理员登录时的HTML代码:(你应该可以在这里看到预算)
<nav id="mainnav-container" ng-if="Engine.hideMainNav != true" class="ng-scope">
<div class="navbar-header">
<a href="/app_dev.php/" class="navbar-brand">
</a>
</div>
<div class="btn-group btn-group-vertical">
<!-- ui-sref-opts="{reload: true}" -->
<a ui-sref="base.engine" ui-sref-active="active" navigator-tooltip="Dashboard" type="button" class="btn btn-default inactive tippy_ez0zu8jgw7xqk4ejjan active" dashboard="" style="position:relative;" href="#!/" rel="tooltip">
<i class="fal fa-fw fa-home" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_6jf7no4muityj8c8ngcs" budgets="" style="position:relative;" href="#!/budget/" rel="tooltip">
<i class="fal fa-fw fa-calculator" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_ieku06frmxanoz20kb5i1" activations="" style="position:relative;" href="#!/activation/?end_date=31-12-2020&start_date=01-01-2020" rel="tooltip">
<i class="fal fa-fw fa-list" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_3f19a78v3ungek4l9ejg6" activities="" style="position:relative;" href="#!/activity/?end_date=30-09-2022&start_date=01-05-2022" rel="tooltip">
<i class="fal fa-fw fa-heartbeat" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_ffkxpknzd1bt8m1jfoso6" manage="" users="" style="position:relative;" href="#!/manage-users/" rel="tooltip">
<i class="fal fa-user-cog" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_stuygjcav39xe0mih4g92" reports="" style="position:relative;" href="#!/reporting-suite/" rel="tooltip">
<i class="fal fa-fw fa-chart-line" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" style=""> Reports</span>
</a>
</div>
</nav>
这是 HTML Laydown 登录时的状态:他只能看到仪表板和活动
<nav id="mainnav-container" ng-if="Engine.hideMainNav != true" class="ng-scope">
<div class="navbar-header">
<a href="/app_dev.php/" class="navbar-brand">
</a>
</div>
<div class="btn-group btn-group-vertical">
<!-- ui-sref-opts="{reload: true}" -->
<a ui-sref="base.engine" ui-sref-active="active" navigator-tooltip="Dashboard" type="button" class="btn btn-default inactive tippy_oq042rw1d68c75d0f67aho active" dashboard="" style="position:relative;" href="#!/" rel="tooltip">
<i class="fal fa-fw fa-home" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_3npvbbn0bod30zndtigtho" activities="" style="position:relative;" href="#!/activity/?end_date=30-09-2022&start_date=01-05-2022" rel="tooltip">
<i class="fal fa-fw fa-heartbeat" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" style=""> Activities</span>
</a>
</div>
</nav>
你可以写一个方法来搜索一个元素,return true
如果它可用 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;
}
}
在你的测试中,
@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.");
}
}
我正在尝试使用具有不同权限的不同用户编写测试用例。 我的情况是有两个用户
- 管理员 - 拥有完全权限
- 具有有限访问权限的 Laydown 用户。
现在我想写一个测试用例,当 Laydown 用户登录并且他看不到他的预算图标时。
他登录时 不存在 预算图标(也未隐藏)所以我不明白如何唯一标识它?我打算使用 IsDisplayed() 方法,但如果图标本身不存在,我该如何选择路径
我想在 Admin 登录时选择路径,但这显然不起作用,因为 Laydown 登录时图标不存在
有什么方法可以断言和测试这个吗?
下面是管理员登录时的HTML代码:(你应该可以在这里看到预算)
<nav id="mainnav-container" ng-if="Engine.hideMainNav != true" class="ng-scope">
<div class="navbar-header">
<a href="/app_dev.php/" class="navbar-brand">
</a>
</div>
<div class="btn-group btn-group-vertical">
<!-- ui-sref-opts="{reload: true}" -->
<a ui-sref="base.engine" ui-sref-active="active" navigator-tooltip="Dashboard" type="button" class="btn btn-default inactive tippy_ez0zu8jgw7xqk4ejjan active" dashboard="" style="position:relative;" href="#!/" rel="tooltip">
<i class="fal fa-fw fa-home" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_6jf7no4muityj8c8ngcs" budgets="" style="position:relative;" href="#!/budget/" rel="tooltip">
<i class="fal fa-fw fa-calculator" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_ieku06frmxanoz20kb5i1" activations="" style="position:relative;" href="#!/activation/?end_date=31-12-2020&start_date=01-01-2020" rel="tooltip">
<i class="fal fa-fw fa-list" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_3f19a78v3ungek4l9ejg6" activities="" style="position:relative;" href="#!/activity/?end_date=30-09-2022&start_date=01-05-2022" rel="tooltip">
<i class="fal fa-fw fa-heartbeat" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_ffkxpknzd1bt8m1jfoso6" manage="" users="" style="position:relative;" href="#!/manage-users/" rel="tooltip">
<i class="fal fa-user-cog" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_stuygjcav39xe0mih4g92" reports="" style="position:relative;" href="#!/reporting-suite/" rel="tooltip">
<i class="fal fa-fw fa-chart-line" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" style=""> Reports</span>
</a>
</div>
</nav>
这是 HTML Laydown 登录时的状态:他只能看到仪表板和活动
<nav id="mainnav-container" ng-if="Engine.hideMainNav != true" class="ng-scope">
<div class="navbar-header">
<a href="/app_dev.php/" class="navbar-brand">
</a>
</div>
<div class="btn-group btn-group-vertical">
<!-- ui-sref-opts="{reload: true}" -->
<a ui-sref="base.engine" ui-sref-active="active" navigator-tooltip="Dashboard" type="button" class="btn btn-default inactive tippy_oq042rw1d68c75d0f67aho active" dashboard="" style="position:relative;" href="#!/" rel="tooltip">
<i class="fal fa-fw fa-home" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" 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" class="btn btn-default tippy_3npvbbn0bod30zndtigtho" activities="" style="position:relative;" href="#!/activity/?end_date=30-09-2022&start_date=01-05-2022" rel="tooltip">
<i class="fal fa-fw fa-heartbeat" aria-hidden="true"></i>
<span ng-show="Engine.offsetMainnav" class="ng-hide" style=""> Activities</span>
</a>
</div>
</nav>
你可以写一个方法来搜索一个元素,return true
如果它可用 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;
}
}
在你的测试中,
@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.");
}
}