Technical Blog

2 Posts tagged with the automated_testing tag

If you've been reading the blog posts by the Elastic Path QA team, you already know that we use Selenium-RC to automate storefront testing and Squish for automated Commerce Manager client testing. Selenium Remote Control (Selenium-RC) is an amazing testing tool, but it only works for web applications running in the browser. Squish is also a great tool, but it only works with desktop applications, like the CM client. For some of our test cases, we need to make changes in the CM client and then verify the changes in the storefront web application. In the past, we had to test this manually, which was time-consuming.

 

Now, we've come up with a way to fully automate this and generate a complete report with the test results. Basically, the strategy is to use a Squish script to invoke Selenium-RC, which then runs our Selenium scripts. This has saved us a lot of time. I'll explain how it works.

 

If you want to try this yourself, you need the following software on your test machine:

  • Java 1.4 or later
  • Ant 1.7.0 or later
  • Firefox 2.0 or later
  • Selenium IDE (for creating test suites and test cases)
  • Selenium RC (for running the tests)
  • Squish for Java

 

Selenium IDE and Selenium server can both be downloaded from the Selenium download page.

 

Also, make sure that Firefox is not remembering passwords; in Firefox,select Tools -> Options -> Security and uncheck the Remember password for sites option.

And if you are using self-signed certificate, a dialog appears when you open EP's account page to confirm that you want to access it. This will break the automated test script, so you need to go to the My Account page in Firefox, accept the certificate, and then close the browser. Next time the page opens (when you run the automated test), the dialog will not appear.

 

Creating your Selenium test project

  1. Use Selenium IDE to create a Selenium suite and test cases.
  2. Create a folder named epautotest. Inside this folder, create a lib folder and a tests folder.
  3. Copy build.xml to the epautotest folder. The build.xml file is the Ant build script, which includes all information Ant needs to run our Selenium tests. You can edit this file to suit your environment. For example, set the testDomain property to the URL of your storefront.

    build xml2.jpg

  4. Copy user-extension.js, summary.xsl, Tidy.jar and selenium-server.jar to  the lib folder.
    • user-extension.js contains functions that extend the base Selenium functionality.
    • summary.xsl is the test report template file.
    • Tidy.jar is the open source library we use to generate the test report.
    • selenium-server.jar is the library required to execute the Selenium tests. (You can get it from your Selenium RC installation.)
    • Copy the Selenium test suite and test cases to the tests folder.
    • Copy your Firefox profile folder (found in C:\Documents and Settings\<your_username>\Application Data\Mozilla\Firefox\Profiles) to the epautotest folder.
    • Modify the build.xml file to point to the copy of your Firefox profile folder.

     

    Running the Selenium tests

    Now, you want to make sure that your Selenium tests run. To run the tests, simply type ant in the epautotest folder. When the tests are finished, a summary can be found in the file test-results\test-summary.html. The folders under test-results mirror the folders under the tests folder and each individual test suite's report can be found under it's relevent folder. Note that the previous test run's results can be found in the test-results.old folder.

    Using Squish to run Selenium tests

    Next, you need to create a batch file that can be invoked by your Squish scripts. This will run the Ant build script that runs your Selenium tests.

    1. Create a batch file in the Squish scripts folder named ep.bat. The contents should look something like this: ant -f c:\epautotest\build.xml
    2. In your Squish scripts, when you want to run the Selenium tests, add a command to invoke the batch file. This command might look like this:

    var i = OS.system("c:\\epautotest\\ep.bat");

     

    We can get the test reports in the c:\epautotest\test-results folder.

    With this fairly simple integration between Selenium and Squish, we've been able to extend automated test coverage and save valuable QA time. If you'd like to see how this works, give it a try. You can use the files I've attached to this post. Let me know if you have questions!

    0 Comments Permalink

    Selenium is a suite of free, community-developed tools for automated testing of web applications. It provides test recording and playback, and supports test playback in both Firefox and Internet Explorer. For our testing purposes, we use two tools in the suite: Selenium IDE and Selenium Core.

    Selenium IDE is a Firefox extension that lets you record, edit, and debug Selenium tests. To start it, launch Firefox and choose Selenium IDE in the Tools menu. In the IDE window, you can create a test suite and record all the test cases you want to make, then save them to your hard drive in the file format of your choice. HTML, Java, C#, Perl, PHP, Python and Ruby are all supported formats, but we save the test cases as HTML so we can re-use them in our IE test suite (more on this later).

    selenium_ide.jpg

     

    Selenium Core can do a lot of things, but we're only interested in the TestRunner tool, which we use to run our HTML test cases in Internet Explorer. To run the test cases, you need to create a test suite file in an HTML editor and add links to the HTML test case files created in IDE. To see how to do this, you can look at the example test suite files included in Selenium Core.

    After that's done, run TestRunner by double-clicking TestRunner.HTA in the Core Dir\Core folder where you unzipped the Selenium Core package. Then enter the path and name of the test suite you want to run in the Test Suite box and click Go.

    selenium_testrunner.png

     

    Real-World Selenium

    For one large customer project, we run test cases against four different online stores in three difference locales. For each store, we've grouped the test cases into a test suite file. This test suite file is the master test case list and can be loaded into either Selenium IDE or TestRunner,depending which browser needs to be tested.

    Installing Selenium IDE

    1. In Firefox, go to http://seleniumhq.org/.

    2. Click the Download tab.

    3. Download the Selenium IDE.

    4. Click Install Now. This will automatically install Selenium IDE in Firefox. You will need to restart Firefox to use IDE.

    Installing Selenium Core

    1. Go to http://seleniumhq.org/.

    2. Click the Download tab.

    3. Download the Selenium Core package to your local system.

    4. Unzip the Core package. TestRunner application is located in the folder where you unzipped Core, under Core Dir\Core.


    0 Comments 0 References Permalink