Verify element visible - Data driven Roles and Access Test

Hi All, hoping you can help me please.

I have an application that manages roles and access via menu items

For example User type Admin should be able to see all menu items, User type Creator should only see the create record menu item, User type Updater should only see the update menu item

I’d like to create a data driven test case for this scenario which would contain the various user types and a TRUE / FALSE for each of the applications menu items to determine if the item should or should not be displayed

Can you advise how I would manage this in the test case assertion please? e.g. User Type is Admin all elements would be set to visible, user type creator only create record would be visible everything else should be false

Any help appreciated

1 Like

There are numerous “verify” statements that can be used.

There is WebUI.verifyElementVisible() and also WebUI.verifyMatch(), so maybe you can test if the menu is visible (if visible, then it’s “true”):

WebUI.verifyElementVisible(findTestObject('menu1'))

or

WebUI.verifyMatch(WebUI.verifyElementVisible(findTestObject('menu1')).toString(), "true", false)

or

import static org.junit.Assert.*

assertTrue (WebUI.verifyElementVisible(findTestObject('menu1')))

Edit: and there is their counter part:
WebUI.verifyElementNotVisible(findTestObject('menu1'))
and
WebUI.verifyNotMatch()

Edit2:
What would you think of a Case Block for which menus should be visible for each of the various users?

Maybe like:
	switch (userAccount)
	{
		case "Admin":
			WebUI.verifyElementVisible(findTestObject('menu1'))
			WebUI.verifyElementVisible(findTestObject('menu2'))
            break;
		case "Creator":
			WebUI.verifyElementNotVisible(findTestObject('menu1'))
			WebUI.verifyElementVisible(findTestObject('menu2'))
            break;
		default:
			WebUI.verifyElementVisible(findTestObject('menu1'))
			WebUI.verifyElementVisible(findTestObject('menu2'))
            break;
	}

Edit: one issue with checking if an element ‘is not visible’ is that it may not be present, in which case, the ‘is not visible’ check says false (element not found). In this case, you should change the test from ‘is not visible’ to ‘is not present’ (with a 2 second timeOut).
WebUI.verifyElementNotPresent(findTestObject('menu1'), 2)