1

What is right way to automate test cases to verify display of ui elements like product filters, images? Can we verify display using IsDisplayed(locator)?or it will be flaky test?

1

In addition to the already mentioned methods I'd like to add that Images are actually tricky. Even if you check if the WebElement is displayed the image might be broken so I recommend to always check if the source is actually available.

Just use something along the lines of

public static Boolean checkSource(String Link) throws Exception{
     HttpUrlConnection Conn = (HttpUrlConnection) new URL(Link).openConnection();
     return Conn.getResponseCode() < 400;
}

That way you can reliably check your Image.

| improve this answer | |
1

You can have the following ways to identify the UI of the element

  • isDisplayed() - To verify the elements gets displayed or not

  • isEnabled() - To verify the web elements is enabled or not

  • isSelected() - To verify the radio button and the combo box is selected or not.

Depends upon the type of the element you can use any of these methods to verify the UI of the elements. You can then assert by printing the output in the console

| improve this answer | |
0

You can now use WebElement.isDisplayed() to check if an element is visible. Then, you can add another assert, which verifies text, and etc ... If you create a good location strategy, your test will work.

| improve this answer | |
  • For UI elements if css attributes changes after particular action by user like if user clicks on link, css class is changed for link So if i assert class of element after click, is that good automation strategy? – gayatri May 16 '18 at 10:54
  • Depends on test strategy/implementation. Each interaction with HTML change something. And yours asserts is to the end of tets, right? So, the best practice is to maintain only locators/selectors, without change anything in your code implementation. – Zhivko.Kostadinov May 16 '18 at 12:58
  • <div class="gridlist-toggle"> <a href="#" id="grid" title="Grid View" class=""></a><a href="#" id="list" title="List View" class="active"></a> </div> – gayatri May 17 '18 at 10:21
  • After link for grid view is clicked, class for grid view is active So can i assert class of grid view link after click to verify view ?As no message is displayed on webpage i am trying to test – gayatri May 17 '18 at 10:25
  • After the click, message is not displayed? What change in all HTML? – Zhivko.Kostadinov May 17 '18 at 14:53
0

It is also important to think about the selectors you use. Long XPath selectors will often break from little tweaks to the UI. Using an id or relative xpath will often save you from failing tests that result from minor edits.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.