My brain hurts, in the peculiar way when you are trying to work out a problem which you know is going to bite you later if you get it wrong. Here is the problem I have been working on and what I think might be the solution.
Problem: I am working on a Selenium scripting framework which will run Java, Python and Ruby Selenium RC scripts as well as ones written in Selenese from the Selenium IDE. Making things dynamic in one of the RC scripts is “easy” as you have the full language behind them. The Selenese ones notso much.
- The application these scripts is for has multiple environments to go through before getting into production, but I only have to care about the first 4.
- The only difference between the environments from a scripting perspective is the login process: different protocol / host / port / username / password. Once you are into the applicaiton proper, things are the same.
- In order to run these scripts (which are “discovered” by the framework), you have to start the Selenium Server with the -htmlSuite option, which means that for a script to be run, it has to be wrapped in a test suite. Not a problem, we can create one dynamically in the framework
- Since we’re making the test suite in the framework, we can inject the correct login script as the first script
But how to pass in the pass in the the username and password values in a way which means the actual scripts are not tailered to one environment? (Hopefully the problem description makes sense).
Solution(?): This is what I have come up with, which unfortunatly is also the most complicated solution (but might buy me a performance improvement a bit down the road)
- Framework discovers a Selenese script
- Framework looks in the test for the “id” of the user which is going to be logged in
<!--start config--> <tr> <td>store</td> <td>superuser</td> <td>userId</td> </tr> <!--end config-->
I’m using ‘store’ because the IDE lets you easily add it which will ease training. I’ll check into CVS a read-only template script which has the config section already done.
- Framework gets the rest of the user’s information from the config file via the id
<!-- users --> <users> <user id="superuser"> <username>adam-super</username> <password>password5</password> <type>super</type> </user> <user id="english fs"> <username>adam-jnh-ca-fs-0002</username> <password>password1</password> <type>fs</type> </user> </users>
- Framework creates the test suite with 2 scripts: the login script and the actual test. The parameters needed for logging in will be passed into the login script.
<html> <table> <tr> <td>IP Filtering (Jonah)</td> </tr> <tr> <td><a target="testFrame" href="login_jonah.html?userName=adam-super&password=password5">Login to CAMS</a></td> </tr> </table> </html>
- Framework looks in it’s configuration to figure out which environment it is working in to get the protocol information
<!-- environmental stuff --> <environment> <protocol>http</protocol> <host>jonah.r1dev.com</host> <port>9080</port> </environment>
- Framework launches the script
- The login script does something along the lines of
<tr> <td>type</td> <td>Login.Token1</td> <td>${userName}</td> </tr>
- Then we are at the generic part of the whole mess where scripts “will just run”
Alternative Solutions I rejected:
- I had thought about using the include user extension to include the login script in each test, but rejected that because
- It breaks the Selenium IDE
- I still have to pass in the various values in the suite
- Using the above solution I could later collect all the Selenese scripts relating to a certain user and run them as a batch instead of at once
- Embed the login values in the login script using ‘store’, but that means
- I have to constantly modify files that are stored in CVS atrifically making it look like there have been revisions
- Avoid point 1 by copying them to a temp dir, but what if the script crashes? They won’t get cleaned up properly
- Embed the login values in the login script in a comment
- see above
- The Selenium IDE overwrites the file when you save it with the new version so anything that would not have been nicely produced by the IDE is wiped out
Is there another option I haven’t thought of or great gaping flaw in what I’ve come up with? I’m coding this up tomorrow.
Any luck with this? I’m looking into something similar.
Yup. See this post
hi adam, i too am working on this generic thing. Im facing a probelm when it comes to a link in a pane in the same window. The generic code does recognise the link where as hard coded code does recognise.
this works fine:
browser.waitForCondition(”selenium.isElementPresent(\”id=ContactFullname\”)”, “30000?);
but this doesnt work:
browser.waitForCondition(”\”selenium.isElementPresent(\\\”id=”+var+”\\\”)\””, “30000?);
can u help me out with this??
My auto-install script creates an html file in the root of the application server with a known name. I store the environment / deployment specific information in a table that I can pull using simple selenese scripts. Since the auto-install application already knows what environment I am installing, it has the information I need to write out to the html file.