The project created using selenium 0.9.2 in Twist uses the wrapper TwistSelenium. Hence migrating to Selenium 2.0 involves creating TwistSelenium class in the test project.
Note -
public ShoppingCart(TwistSelenium selenium, ... ) {
this.selenium = selenium;
.....
...
}
should be changed to
public ShoppingCart(TwistSelenium selenium, ... , WebDriver browser) {
this.selenium = selenium;
.....
...
this.browser = browser;
}
Limitations
Currently Twist does not provide out of the box support to run webdriver tests using Selenium 2 Grid. Follow the instructions below to run Twist tests in Selenium 2 Grid.
1. Add the attached file CustomWebdriverFactory.java in the "src" folder of the Twist Project (with Selenium 2 as driver) in package com.thoughtworks.twist.driver.webdriver.
2. Replace applicationContext-suite.xml file in the "src" folder with the file attached.
3. Add a property in twist.properties located in "src" folder
webdriver.grid.server=http://localhost:4444/wd/hub
4. Export the ant build file for the project and add the twist target. Change the number of threads to 2 or more in the Twist target "execute-scenarios". Checkout "http://www.thoughtworks-studios.com/twist-agile-test-automation/2.3.1/help/how_do_i_run_scenarios_from_ant.html#using_ant_integration" to export ant build file for a Twist project.
5. Export the Twist libraries for the project (Scenarios View-> Right click on the project->Export Twist Libraries) to a particular location.
6. check "http://code.google.com/p/selenium/wiki/Grid2' to run the hub and the "Selenium Webdriver" nodes
- Use the selenium-server-standalone-***.jar that is available in exported Twist library folder to run the commands
7. Go to Config GUI in Twist and set browser to Firefox
8. Run the build target "execute-scenarios" in build.xml from Twist IDE
This will start as many firefox browsers as you have mentioned in the "execute-scenarios" target (You can only run 5 threads per node by default)
To run tests in Chrome
- Set the browser type in Twist Config GUI to chrome
- Start the Webdriver node like before along with additional argument "webdriver.chrome.driver" which points to Chrome server
- For e.g.
java -Dwebdriver.chrome.driver=<pathToChromeServerBinary> -jar selenium-server-standalone-2.3.0.jar -role webdriver -hub http://localhost:4444/grid/register
<pathToChromeServerBinary> is available under - <exported Twist library folder>/com.thoughtworks.webdriver.recorder_1.0.0.11210/tools
To run tests in IE
- Set the browser type in Twist Config GUI to IE
- Start the Webdriver node like before along with additional arguments browserName and platform for browser option
- For e.g.
java -jar selenium-server-standalone-2.3.0.jar -role wd -hub http://localhost:4444/grid/register 5556 -browser browserName="internet explorer",platform=WINDOWS
- You can only run one instance of IE browser in each node
Limitations
Screenshots provided as part of Twist Reporting will not be accurate. You need to rely on stack trace provided by the report to diagnose the script issues.
Cheers,
Vinay/Nishant/Jagannath
I recorded an action using the Selenium IDE and used the File->Export Test Cases as Python 2 (Remote Control) format.
I am using Selenium RC 2.3.0
I then ran the script from command prompt but it throws an exception.
The exported Python 2 RC code is:
from selenium import selenium
import unittest, time, re
class login(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "http://
testServer1/")
self.selenium.start()
def test_login(self):
sel = self.selenium
sel.open("/WebAccess/login.html")
sel.type("id=LoginID", "Administrator")
sel.type("id=Password", "Administrator")
sel.click("id=login")
sel.wait_for_page_to_load("30000")
sel.click("link=Home") # This is where it fails.
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
At this line - sel.click("link=Home") it fails with the exception
======================================================================
ERROR: test_login (__main__.login)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Documents and Settings\User\Desktop\login.py", line 16, in
test_log
in
sel.click("link=Home")
File "C:\Python27\lib\selenium\selenium.py", line 290, in click
self.do_command("click", [locator,])
File "C:\Python27\lib\selenium\selenium.py", line 217, in do_command
raise Exception, data
Exception: ERROR: Element link=Home not found
----------------------------------------------------------------------
I even tried increasing the 30000 to 60000 but still no help. I can see the page is loaded fully and waiting for a while because of the higher timeout. However when executing this link=Home it fails.
The HTML code is:
<div class="links nopreview">
<span><a class="csiAction" href="/WebAccess/home.html#URL=centric://
REFLECTION/INSTANCE/_CS_Data/null">Home</a></span>
<span> • </span>
<span><span><a class="csiAction" href="/WebAccess/
home.html#URL=centric://SITEADMIN/_CS_Site">Setup</a>
</span><span> • </span>
</span><span><a title="Sign Out" class="csiAction csiActionLink">Sign
Out</a></span>
</div>
The recorded actions using IDE are:
<tr>
<td>open</td>
<td>/WebAccess/login.html</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=LoginID</td>
<td>Administrator</td>
</tr>
<tr>
<td>type</td>
<td>id=Password</td>
<td>Administrator</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=login</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Home</td>
<td></td>
</tr>
I did run the test using IDE's recorded script. It works great. I was able to login and click on the Home link too. However, it fails with that exception when I wanted to run it using Python's Unittest with Selenium Server 2.3.0.
I tried sel.click('//a[contains(text((),"Home")]') and it throws the exception
Traceback (most recent call last): File "C:\Documents and Settings\User\Desktop\login.py", line 17, in test_log in sel.click('//a[contains(text((),"Home")]') File "C:\Python27\lib\selenium\selenium.py", line 290, in click self.do_command("click", [locator,])
File "C:\Python27\lib\selenium\selenium.py", line 217, in do_command raise Exception, data Exception:
ERROR: Invalid xpath [2]: //a[contains(text((),"Home")]
I even tried sel.click('xpath=//a[contains(text((),"Home")]') and it still throws the same exception as mentioned in the above comment. I wonder what could be wrong. If I comment the line that clicks on the Home link then it runs fine. Its the problem with clicking this link.
To add, not only for Home. It does not work for Home or Setup or even Signout for that matter. It does not work for any of the links in that div. However playing back the recorded script works fine!
Any suggestions or guidance, please?
Hello,
Possibly more of a Selenium issue than a Twist issue, so thought it best to post here.
I'm looking to take a screenshot of the browser whenever a test fails. I have them up & running fine for each test, but it will fill up space very fast to constantly take screenshots of passing test steps.
Anyone have any advice on how I should go about this?
Hi,
Could you please tell me how to run in different browthers scenarios which were recorded by twist using selenium driver and firefox?
Thanks a lot!
Hi All,
I am facing problem with uploading a file using selenium ( Java). If any one have the solution, please revert back to the following email id with necessary external files to be added to my project in order to run the script.
My email id : tester26.tester@gmail.com
Your reply is appreciated.
Thanks in advance.
Hi,
I'm trying to upload a file as part of a test I'm currently writing, but when I replay the test the filename isn't supplied to the file upload control and therefore the required field validation fails when the form submits. The selenium code generated is as follows:
selenium.type(ctl00_cphMain_fvSubjectConsent_fuScannedForm, "test.png");
Any ideas?
Thanks,
James
Hi,
I am writing a basic script of opening a website in twist using selenium. After execution of my script the execution window closes by itself. I want to keep that window in open state.. can someone help me in this?
Cheers,
Preeti