我正在嘗試使用具有不同權限的不同用戶撰寫測驗用例。我有兩個用戶的情況
- 管理員 - 具有完全權限
- 具有有限訪問權限的用戶。
現在我想在 Laydown 用戶登錄并且他無法看到他的預算圖示時撰寫一個測驗用例。
登錄時預算圖示不存在(也沒有隱藏),所以我不明白如何唯一標識它?我打算使用 IsDisplayed() 方法,但是如果圖示本身不存在,我該如何走
我雖然在管理員登錄時采取了路徑,但這顯然不起作用,因為當 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>
這是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_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>
uj5u.com熱心網友回復:
您可以撰寫一個方法來搜索一個元素,true如果它可用則回傳,否則回傳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.");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/473975.html
