DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Brief Guide to Testing Browser Behavior with Selenium IDE and CFSelenium

Brief Guide to Testing Browser Behavior with Selenium IDE and CFSelenium

Brian Swartzfager user avatar by
Brian Swartzfager
·
Apr. 22, 11 · Web Dev Zone · News
Like (0)
Save
Tweet
8.20K Views

Join the DZone community and get the full member experience.

Join For Free

The Selenium IDE Firefox plugin makes it easy to record the actions you perform on a web pages or series of web pages as a set of commands.  You simply open the Selenium IDE tool from the "Tools" menu in Firefox, make sure the Record button (the red circle in the upper right) is active, and then click and type away.  Once you've stopped recording, you can re-run the the recorded steps any number of times and even save the steps as a test case file to run again later.

Screenshot of Selenium IDE

Simply recording your actions as described above can be useful when you're troubleshooting a browser behavior (usually a Javascript function) that only executes after you've changed certain form fields or performed particular actions:  it saves you the time of constantly reloading the page and manually going through the actions again.  But you don't end up with an actual verifiable test:  you're verifying whether or not the page is behaving correctly by visually observing the outcome each time.  In order to use Selenium (and especially CFSelenium within the context of MXUnit) as a true testing tool, you need to add verification and assertion statements into your Selenium recordings.

Fortunately, it's easy to add such statements with Selenium IDE.  If the browser behavior results in a visible change to the page (like updating text in a form field), right-click on the changed part of the page.  At the bottom of the context menu that appears will be several Selenium commands you can choose to add to your current recording.  One or more of the commands will be a "verify" or "assert" command that you can add to your recording that basically means "return true if this page element contains this value or this text; return false if not".

Take the example below.  If the user selects "College" from the first select box on the bottom line, an AJAX call is made that populates the third select box on that line with the acronyms of the various colleges.  When I right-click on that third select box, I can select the verification command that verifies whether or not the select box contains all of the acronyms (you can see all of the text labels for the options in the select are concatenated together).  Other verfication and assertion commands for the element you selected might also be available under the "Show All Available Commands" option at the bottom of the context menu.

Screenshot of selecting a verification command

It's these verfications and assertions that you save in your recording that form the basis for your testing with CFSelenium and MXUnit.  When you export your Selenium recording as a CFSelenium/MXUnit test case and then run it, MXUnit is going to receive the results of the verifications/assertions from the Selenium Server and report the test case as having passed or failed based on those results.  When your CFSelenium/MXUnit test case passes in Firefox, you can then use CFSelenium to run the test case against other browsers and see if it passes or fails.  If it fails in Browser X, you can look at the test results to see which verifications/assertions failed and then figure out how to modify your page's behavior/Javascript so that it works in that Browser X...and once it works in Browser X, you'd re-run the test for Firefox and the other browsers to make sure the newly modified page still passes the tests in those browsers.

If you're running CFSelenium on ColdFusion 8 or 9 in conjunction with MXUnit, you can add MXUnit debug() statements to your test cases to retrieve additional information from the test (beyond the success or failure of the verifications or assertions).  For example, you could add the following line to your MXUnit test case to retrieve all of the text on the web page used in the test:

debug(selenium.getBodyText());

For more information about the debug() statement, consult the MXUnit documentation. For more information about what kinds of data CFSelenium can return from the test, look through the functions and read the hints in the relevant CFSelenium .cfc file (selenium.cfc for ColdFusion 9, selenium_tags.cfc for ColdFusion 7 and 8).

Integrated development environment Test case Testing

Published at DZone with permission of Brian Swartzfager, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 9 Strategies to Improve Your Software Development Process
  • Usage of Java Streams and Lambdas in Selenium WebDriver
  • How to Test JavaScript Code in a Browser
  • AMI and Snapshot Management Using AWS Lambda

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo