Most of the times we do have hidden div tags which need to be verified.
In most of the test designs, the first step towards testing a particular application is to verify that all the elements exist on the application under test.
Example:
Lets say we have a login page which has two text-fields. One for username the other for password. On the page, we also have a hidden div tag which is used by the developer to pass on the login failure message.
Usually its hidden but is set to visible when there is a login failure.
In usual test designs we would want to do something like this at the first step.
1. test all the components exist:
2. Then give an incorrect username and password
3. Now verify that the label for the failure message exists
When you run this test script, it fails!!!!!
Why?
The reason it fails is because you have the visible property of the div tag set to NONE initially! Selenium tries to verify if the element exists too early...
So how to resolve this issue?
Solution
There is one straightforward solution for testing - the simplest one is to use a "wait" command. That is when you know or can estimate the time the element will appear on the application.
The answer is to use "waitFor" commands. These commands are specifically designed to test ajax elements. We usually have this situation where a particular element is accessible only after a set of user actions. Thus we can waitFor a particular condition and then use "verify" commands to complete the test case.
Thus now we will have to use the following commands.
Hope this helps!!!
In most of the test designs, the first step towards testing a particular application is to verify that all the elements exist on the application under test.
Example:
Lets say we have a login page which has two text-fields. One for username the other for password. On the page, we also have a hidden div tag which is used by the developer to pass on the login failure message.
Usually its hidden but is set to visible when there is a login failure.
In usual test designs we would want to do something like this at the first step.
1. test all the components exist:
verifyTrue(selenium.isElementExists(LoginPage.username)); verifyTrue(selenium.isElementExists(LoginPage.password));
2. Then give an incorrect username and password
selenium.type("LoginPage.username","SomeUserName");selenium.type("LoginPage.password","SomePassword");
3. Now verify that the label for the failure message exists
verifyTrue(selenium.isElementExists(LoginPage.loginFailureDiv));
When you run this test script, it fails!!!!!
Why?
The reason it fails is because you have the visible property of the div tag set to NONE initially! Selenium tries to verify if the element exists too early...
So how to resolve this issue?
Solution
There is one straightforward solution for testing - the simplest one is to use a "wait" command. That is when you know or can estimate the time the element will appear on the application.
The answer is to use "waitFor" commands. These commands are specifically designed to test ajax elements. We usually have this situation where a particular element is accessible only after a set of user actions. Thus we can waitFor a particular condition and then use "verify" commands to complete the test case.
Thus now we will have to use the following commands.
waitForCondition("selenium.browserbot.getElementById('LoginPage.loginFailureDiv').disabled == false", "1000");verifyTrue(selenium.isElementExists("LoginPage.loginFailureDiv"));There are other commands which can be helpful while testing AJAX elements: waitForElement(), waitForElementPresent(), waitForVisible() :)
Hope this helps!!!
Comments