
Selenium FAQ
Table of Contents [-]
- Introduction
- Q&A
- Why do you create one page for every portlet that is being tested? Wouldn’t it be more efficient if you had one single page to test the portlets?
- When the tests for a portlet conclude why don’t we delete the portlet data? Then rebuilding the database won’t be necessary.
- Why do you use the ‘click’ command at times and then the ‘clickAndWait’ command at others? What’s the difference?
- Where and when should I use wait commands (waitForElementPresent, waitforTextPresent)?
- What is the ‘pause’ command and when should I use it?
- What is the difference between a wait command and an assert command (assertElementPresent, assertTextPresent)?
- Why do you use the ‘typeKeys’ command and then follow that command up with ‘type’ with the exact same text? In addition – I noticed some typos when you wrote the values for the ‘typeKeys’ commands!
- I see that there are .html and .java files in the test directories – can I just make .java files to test with?
- In test-portal-web.properties why do you default to using Firefox’s Chrome mode? Are there any consequences of running the tests in regular Firefox or even IE7?
- I’m trying to run the tests on a different app server but they keep failing! My tests are continually timing out!
- Why do you create one page for every portlet that is being tested? Wouldn’t it be more efficient if you had one single page to test the portlets?
- Related Articles
Introduction #
In this wiki article we’ll try and answer any questions that we’ve been asked about Selenium testing and if you have any more questions to ask about it feel free to add it into comments and we’ll add it to this FAQ with an answer.
Q&A#
Why do you create one page for every portlet that is being tested? Wouldn’t it be more efficient if you had one single page to test the portlets?#
A: There are several reasons why we decided early on to test one portlet per page. Our first reason was that we wanted to isolate the portlets under test so that our results would not be polluted with any other possible outside interference. Another reason was that we wanted to minimize complexity for Selenium RC locating inputs/icons/fields so that there would be fewer cases where an incorrect button/input would be clicked or inadvertently changed.
When the tests for a portlet conclude why don’t we delete the portlet data? Then rebuilding the database won’t be necessary.#
A: We recognize that there is space to improve our automated test suites in terms of breadth (number of features tested) and depth (number of tests per feature). Knowing that, in many cases we prefer to leave the data from a portlet so that it can be used later to write tests for, either that portlet, or another. A great example of this would be our tests for the Blogs portlet and Blogs Aggregator portlet. In that case we realized that it would be more advantageous to leave the data from the Blogs portlet so that it can be leveraged to test other portlets instead of testing the Blogs Aggregator and having to create a brand new Blog entry specifically for it.
Why do you use the ‘click’ command at times and then the ‘clickAndWait’ command at others? What’s the difference?#
A: In general we shy away from using the ‘click’ command. In most scripting cases it is desirable, if not required to use ‘clickAndWait’. Using ‘clickAndWait’ will click on an element and then pause the test until the following page has been loaded. In most cases this is necessary to keep the test from moving too quickly and looking for elements that have not yet been rendered. However, as we’ve tested we’ve run into a handful of cases where it was necessary to utilize a ‘click’. In certain situations it will take a page much longer to be technically ‘loaded’ then Selenium’s 30 second global timeout limit. An example of this would be when trying to add an entry in the Blogs portlet. The page does not necessarily ever finish being loaded but all the necessary elements are in place – in this case the Selenium test would hang for no reason other then to wait for the page to completely load. Instead of dealing with that we used the ‘click’ command to jump to the next page and scripted the test to wait until only the elements it needed to use were loaded before continuing on with the test. Please see the AddEntryTest.html in the Blogs test for an example.
Where and when should I use wait commands (waitForElementPresent, waitforTextPresent)?#
A: When starting a new test we almost always like to invoke a wait command – this is good practice because if your tests are invoking many page loads you definitely don’t want your test to start until the element or text you need is present on the page. At the beginning of the test it is a precautionary measure. In other areas we use it as a tool to confirm the results of an action that might take some time to load. Please see the above question for some practical ways that we’ve used the ‘waitForElementPresent’ command in tests.
What is the ‘pause’ command and when should I use it?#
A: The ‘pause’ command is a command that can initiate a user decided timeout for the test up to 30 seconds. (This can be modified higher if one changes the global timeout timer in Selenium, not covered in this document). This command is idea for times when you know a test will be waiting more then 30 seconds for a certain action to have been completed. In our case, we’ve used ‘pause’ to precede waitForElementPresent commands so that in the final results the waitFor command does not fail. An example of this can be seen in our tests for Session Expiration.
What is the difference between a wait command and an assert command (assertElementPresent, assertTextPresent)?#
A: When a ‘wait’ command is executed it will check for the specified element every second for 30 seconds before it fails – used well for tasks that as expected to take time to produce measurable results. An ‘assert’ command is different in that as soon as the command is executed it will check for the element and if the element is not present it will fail the current test in the suite. This is a good command to use if you have specific results that you are expecting specific results from a test and would like the test to fail right away so that you can locate the issue right away instead of waiting up to 30 seconds to only be told something you could have been told in one second.
Why do you use the ‘typeKeys’ command and then follow that command up with ‘type’ with the exact same text? In addition – I noticed some typos when you wrote the values for the ‘typeKeys’ commands!#
A: This is related to a very specific bug that occurs in both Selenium IDE and the Selenium RC. Basically Selenium doesn’t always correctly type certain characters – one in particular that it misinterprets is ‘y’, which it will interpret as pressing the ‘alt’ key on your keyboard. Obviously this caused a lot off instability until we added a workaround to the tests. This of course begs the question – why do we even use ‘typeKeys’ to begin with when we could just use ‘type’. In some cases it is necessary to use ‘typeKeys’ to fire off any javascript triggers that enable button presses. Whereas the ‘type’ command would simply insert the text you desire into the field ‘typeKeys’ will actually simulate keys being pressed for the browser. An example where this was necessary is in adding and editing blog comments. To overcome this we overlapped the type commands on each other: a first time through with ‘typeKeys’ to fire off any necessary key press events and without any problem characters (y) and then a second time through with ‘type’ to make sure the correct text has been inputted. So the typos were intentional – at least most of them!
I see that there are .html and .java files in the test directories – can I just make .java files to test with? #
A: Please do not just script .java files to test with – in an effort to make everything as accessible as possible and keep the code from becoming too polluted you must code the tests in their .html format first and then auto-generate the .java code using the selenese-to-java converter which will generate code in proper form. For more information about auto-generating the code please see Selenium Testing.
In test-portal-web.properties why do you default to using Firefox’s Chrome mode? Are there any consequences of running the tests in regular Firefox or even IE7?#
A: Great question! We default to Firefox’s Chrome mode because in this mode we’re able to most easily bypass some of the basic javascript security restrictions that would keep us from testing things like uploading files. Because we frequently like to test the uploading of .lar files we tend to run the tests in Chrome, however previous to defaulting to Chrome we ran out tests without issues in FF2 and FF3. Testing in IE7 and IEHTA (Internet Explorer’s equivalent for Chrome) is currently not entirely supported and any tests in that mode are purely experimental, though we are working to see what can be done to enable parity between our tests in FF and IE.
I’m trying to run the tests on a different app server but they keep failing! My tests are continually timing out!#
A: We’re sorry to hear that! We generally use Tomcat as our baseline app server because of its quick response time and have scripted our tests as such – however it should be a relatively simple question of extending the time of your global timeout for Selenium to be in alignment with the response time for whatever app server is being tested. Please see http://selenium-rc.openqa.org/options.html for options when running the Selenium Server.