Selenium

Make ‘store’ command work with Selenium RC to pass values between test cases

Stored variables do not get passed between test cases in selenium-server-standalone-2.8.0. This might get fixed in the future but here is a work around for now that we used for our testing.

Example

Test case 1 – Store the Google URL in the url variable

<tr>

<td>store</td>

<td>http://www.google.com</td&gt;

<td>url</td>

</tr>

Test case 2 – open the Google URL stored in the previous test case

<tr>

<td>open</td>

<td>${url}</td>

<td></td>

</tr>

Issue

The url variable is empty in the second test.

Solution

In Windows, go to the directory of the selenium .jar file

1. Open the file (selenium-server-standalone-2.8.0.jar) with win RAR.

2. Go to core\scripts\selenium-testrunner.js

3. Open the file and search for the “startTest” function.

4. Move the following lines from the function “startTest” to the beginning of the function “startTestSuite”:

storedVars = new Object();

storedVars.nbsp = String.fromCharCode(160);

storedVars.space = ‘ ‘;

5. Save the File and let the system pass the changes to the .jar as well.

The ‘store’ command should work!

– by Thierry Sequeira

Advertisements

About michellesequeira

http://www.mumbl.co.uk

Discussion

9 thoughts on “Make ‘store’ command work with Selenium RC to pass values between test cases

  1. Thank you for saving my life 😀

    Posted by SomeRandomGuy | November 7, 2011, 10:28 pm
  2. Glad it worked and thanks for your feedback 🙂

    Posted by thierrysequeira | November 7, 2011, 10:44 pm
  3. Thanks for this!

    Do you know if there is an issue for this in their issue tracker?

    Posted by Markos Fragkakis | November 15, 2011, 3:53 pm
  4. How can this be translated to a Junit .java class / code snippet?
    When i try to use a junit java class Selenium object does not “know of” the “store” command and indicates introducing a ‘cast’ to the Selenium object.

    Example (code in Eclipse Selenium project):

    import com.thoughtworks.selenium.*;
    import org.junit.*;
    import static org.junit.Assert.*;
    import static org.hamcrest.CoreMatchers.*;
    import org.openqa.selenium.*;

    public class SetLoginParams {
    Selenium selenium;
    @Test
    public void testSetLoginParamsForBrad() throws Exception {
    selenium.store(“brad”, “userName”);
    selenium.store(“xxx123yyy”, “userPassword”);
    }
    }

    Thanks

    Posted by Bey | December 25, 2012, 12:44 am
  5. It totally worked for me, in the latest version (selenium-server-standalone-2.28.0).

    Thanks

    Posted by Nuno Estrada | January 29, 2013, 3:41 pm
  6. It is still an issue in the latest version.(selenium-server-standalone-2.28.0)
    But you can solve it as told above.
    Thank you very much.

    Posted by hdhd | February 7, 2013, 8:21 am
    • Hello,

      I’m trying to implement this solution with version 2.28.0 but it does not work.
      I opened the jar selenium-server-standalone-2.28.0.jar, changed the file selenium-testrunner.js.
      Here is my start function:
      startTestSuite: function () {
           storedVars = new Object ();
               storedVars.nbsp = String.fromCharCode (160);
               storedVars.space = ”;
               this.controlPanel.reset ();
               this.metrics.resetMetrics ();
               this.getTestSuite (). reset ();
               this.runAllTests = true;
               this.runNextTest ();
           },

      There was there a mistake?

      Thank you in advance.

      Posted by Emmanuel | February 7, 2013, 1:33 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archive

Recent Posts

%d bloggers like this: