Selenium IDE WebDriver Formatters Updated to Support TextPresent Commands

Wow! Time flies! It has been over a year that I added the WebDriver exporters for the four officially supported languages to Selenium IDE. You must have read my post about it. Today I finally updated the WebDriver formatters to support six new commands. These are assertTextPresent, verifyTextPresent, waitForTextPresent, assertTextNotPresent, verifyTextNotPresent, waitForTextNotPresent. If you have been using any of these commands, you would have seen the following comment in the exported code:-

// ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]

Now it should give you a working solution in most of the cases.

Why so long and how does it work?

Tons of factors contributed to the delay. One of them is that IsTextPresent generated commands like verifyTextPresent and others are probably my least favourite Selenese commands. There are times when they are unavoidable. I personally feel that they are often overused. These commands retrieve the full text of the web page and check it. Often, this is very inefficient. It is better to find the exact element where you expect the text to appear and use a verifyText or a similar command instead. The smaller the element that you manage to find the more efficient your test will be. Keep this in mind and try to avoid the *TextPresent commands if you can.

Another reason is the current implementation of the formatters made it hard. I tried to reuse as much code as possible from the existing formatters. A consequence of this was that most commands use the equals or not equals as a basis of their verification or assertions. The TextPresent commands used contains instead of equality. There was no support for a contains verification or assertions and adding support meant adding this support to every supported language. Finally, I found way to avoid this, but it is a bit complicated. I simply change the *TextPresent command to a *Text command and modify the pattern so it would work. For example, the following verifyTextPresent command is changed to a verifyText command.

verifyTextPresent | My text found!
verifyText | css=BODY | glob:*My text found!*

This change is silently performed before exporting. While this usually works, there are a few challenges.

Since you can give an exact pattern or a regexp pattern, the converted pattern is a bit tricky may not always work as expected. Currently, exact patterns are converted to a glob pattern. If you have a * or a ? in your exact pattern, the behaviour will now change. I am working on a different strategy, and based on your feedback, I will decide to implement it in the future. In this version, there is an extra comment that warns you about needing manual changes to the exported command.

// Warning: assertTextPresent may require manual changes

As you all know, we need your help. Tell us if you find something not as expected and we will try to fix it. This will be available in the next version of Selenium IDE or in the nightly build.

Follow samitbadle on Twitter

This entry was posted in Selenium IDE and tagged , , , , , , , , , . Bookmark the permalink.

2 Responses to Selenium IDE WebDriver Formatters Updated to Support TextPresent Commands

  1. genwise says:

    Hi Samit,

    Have any plan to release Perl Selenium IDE WebDriver Formatter?


Leave a Reply to Samit Badle Cancel reply

Your email address will not be published. Required fields are marked *