Get Instance
Using The Maveryx Test Automation Framework sometimes you could encounter the “multiple objects found error“. This error occurs when the intelligent Maveryx search and recognition engine is not able to distinguish between two or more objects. This may happen if the AUT’s (Application Under Test) UI has two or more identical objects in the same container with no other info to discern which is the right one.
Imagine, for example, a frame with some text areas and some “browse” buttons associated. Asking Maveryx to click on one of these buttons will let fail the test because of the “multiple objects found error“.
In a case like this, even a manual tester will have problems. The only way to let the tester discerning which object is the correct one is giving her at least the information about its position respect the others: the first, the second, the last, etc…
It is possible to do the same with Maveryx by using the function getInstance(int position) by specifying the value of the “position“.
In the following test script, we are going to test a very easy AUT with 5 text areas and 5 associated “browse” buttons. In this case, we want to click on the first button.
/**
* This Test Case provides an example of managing multiple instances of the same objects by the relavant Maveryx APIs.
* @throws Exception
*/
@Test
public void clickTheFirst() throws Exception {
//the button to test
GuiButton button = new GuiButton(“Browse“);
button.getInstance(0).click(); //click the first button
GuiLabel message = new GuiLabel(“message“);
assertEquals(“You pressed the first Browse button!”, message.getText()); //check expected message has been displayed
}
Alternatively, we can write the test through a codeless approach based on keywords.
In the following xls file we wrote the same automated test script by using the Maveryx keywords.
In both the executions, the Maveryx Test Automation Framework successfully located at runtime the right “Browse” button and clicked on it.
Have you encountered a problem like this in your test automation experience? In case, how did you fixed it?