Ensuring a divs content has changed over time in Selenium - selenium

I have a div that contains a slideshow. ( http://film.robinhoodtax.org/issues/education )
I am using Selenium to test it. So far I have been using the HTML/Selenium script below to validate that the slideshow is actually working. But my assertEval is failing.
How can I correctly detect the slideshow and make sure it is moving?.
You can see I've approached this by storing the HTML and waiting then trying again but it isn't working.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/issues/education</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td></td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>css=div[id='views-nivo-slider-ImagesGallery-block_1']</td>
<td></td>
</tr>
<tr>
<td>storeHtmlSource</td>
<td>css=div[id='views-nivo-slider-ImagesGallery-block_1']</td>
<td>first</td>
</tr>
<tr>
<td>pause</td>
<td>3000</td>
<td></td>
</tr>
<tr>
<td>storeHtmlSource</td>
<td>css=div[id='views-nivo-slider-ImagesGallery-block_1']</td>
<td>second</td>
</tr>
<tr>
<td>assertEval</td>
<td>${first} == ${second}</td>
<td>second</td>
</tr>
</tbody></table>
</body>
</html>

Looking at the site under test, you could check the active page of the slideshow using the following:
verifyText | css=a.nivo-control.active | 0
waitForText | css=a.nivo-control.active | 1
waitForText | css=a.nivo-control.active | 2
waitForText | css=a.nivo-control.active | 3
waitForText | css=a.nivo-control.active | 4
waitForText | css=a.nivo-control.active | 5
waitForText | css=a.nivo-control.active | 6
waitForText | css=a.nivo-control.active | 7
waitForText | css=a.nivo-control.active | 0
This will wait until the active 'page' changes through each available slide, and then check that it loops back to the first slide. This is better than an a pause, as this way you only wait as long as it take for the slide to change.

Related

Selenium IDE 2.9.1 is not showing the selenium script after recording

I just installed selenium IDE 2.9.1 and recorded a testcase. But when inspect the source, It is showing only the HTML, not selenium script.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.google.co.in/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/?gws_rd=ssl</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=Passwd</td>
<td>arunkojndfjn</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=signIn</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
What to do to get the selenium script ? Thanks.
Convert a selenium IDE script into one that can be run in Webdriver isn't done by viewing the file, as the file itself is written in a selenium specific format of HTML. You need to use the options within selenium IDE itself. If you go to "File > Export Test Case as" you will get a list of various languages you can export the test as.

Using Selenium IDE to act on a Popup

I have an application that still uses popup windows over Modals, and we need to test the behavior of some of the popups. In my current stage of research it appears the failure occurs on a waitForPopup call. To confirm this, I made a basic HTML page to throw a popup when a link is clicked (easily simulated with IDE)
<html>
<head>
<title>Test Popup</title>
</head>
<body>
Click Me
</body>
<script>
function openwindow() {
var i, l, options = [{
value: 'first',
text: 'First'
}, {
value: 'second',
text: 'Second'
}],
newWindow = window.open("", "popup1", "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
newWindow.document.write("<select onchange='window.opener.setValue(this.value);'>");
for(i=0,l=options.length; i<l; i++) {
newWindow.document.write("<option value='"+options[i].value+"'>");
newWindow.document.write(options[i].text);
newWindow.document.write("</option>");
}
newWindow.document.write("</select>");
}
function setValue(value) {
document.getElementById('value').value = value;
}
</script>
</body>
And the Selenium test case
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhost.localdev.com/" />
<title>localpopuptest</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">localpopuptest</td></tr>
</thead><tbody>
<tr>
<td>click</td>
<td>id=click_me</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=click_me</td>
<td></td>
</tr>
<tr>
<td>waitForPopUp</td>
<td>popup1</td>
<td>30000</td>
</tr>
<tr>
<td>assertTitle</td>
<td></td>
<td>Test Popup</td>
</tr>
</tbody></table>
</body>
</html>
This seems to be a common issue, is there a better way to track and assert popup windows?
Check this out:
click | id=click_me
selectWindow | popup1
select | //select | Second
If your popup has a dynamic content you can just add:
waitForElementPresent | //select
after selectWindow.

Selenium + include + loadTestData results in 'testCase.debugContext.currentCommand is undefined'

I've got an issue with Selenium in combination with user extensions:
-datadriven
-flowcontrol
-includeCommand
as referred by the following post:
Issue running Selenium IDE test suite using Selenium Standalone server
I've got different versions of the user-extensions named above that I use in the Selenium IDE. I'll post the exact ones because the problem might be in there.. The reason I mention the SO post above is because I get the same error when I run the testsuite directly via Selenium Core.
Alright, introduction with environment description done, on to the serious work:
If I run my testsuite, the loadTestData will execute properly and I can echo the variables which reside in the data.xml file in the while loop. When I include another testcase, I can also echo the variable I just saved or passed through directly. The error occurs at the end of the while loop, when endWhile is being executed.
I get the following log with in the end the errors:
[info] Playing test case LoadTestData
[info] Executing: |setSpeed | 1000 | 1500 |
[info] Executing: |loadTestData | data.xml | |
[info] Executing: |while | !testdata.EOF() | |
[info] Executing: |nextTestData | | |
[info] <test q="test1"/>
[info] Executing: |echo | ${q} | |
[info] echo: test1
[info] Executing: |store | ${q} | query |
[info] Executing: |echo | ${query} | |
[info] echo: test1
[info] Executing: |include | ./something.html | |
[info] Executing: |begin$Template$ | ./something.html | |
[info] Begin Template ./something.html at position 8
[info] Executing: |store | http://www.google.com | url |
[info] Executing: |open | ${url} | |
[info] Executing: |echo | ${query} | |
[info] echo: test1
[info] Executing: |sendKeys | id=gbqfq | ${query} |
[info] Executing: |end$Template$ | ./something.html | |
[info] End Template ./something.html at position 8
[info] Executing: |endWhile | | |
[error] testCase.debugContext.currentCommand(...) is undefined
[error] Unexpected Exception: TypeError: testCase.debugContext.currentCommand(...) is undefined.
This is the contents of the various files I use:
IDE.html (suite):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Test Suite</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium">
<tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td>LoadTestData</td></tr>
<tr><td>something</td></tr>
</tbody></table>
</body>
</html>
testcases:
LoadTestData.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="D:/demo/" />
<title>LoadTestData</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">LoadTestData</td></tr>
</thead><tbody>
<tr>
<td>setSpeed</td>
<td>1000</td>
<td>1500</td>
</tr>
<tr>
<td>loadTestData</td>
<td>data.xml</td>
<td></td>
</tr>
<tr>
<td>while</td>
<td>!testdata.EOF()</td>
<td></td>
</tr>
<tr>
<td>nextTestData</td>
<td></td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${q}</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>${q}</td>
<td>query</td>
</tr>
<tr>
<td>echo</td>
<td>${query}</td>
<td></td>
</tr>
<tr>
<td>include</td>
<td>./something.html</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
something.html
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="D:/demo/" />
<title>Something</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Something</td></tr>
</thead><tbody>
<tr>
<td>store</td>
<td>http://www.google.com</td>
<td>url</td>
</tr>
<tr>
<td>open</td>
<td>${url}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${query}</td>
<td></td>
</tr>
<tr>
<td>sendKeys</td>
<td>id=gbqfq</td>
<td>${query}</td>
</tr>
</tbody></table>
</body>
</html>
testdata:
<testdata>
<test q="test1"></test>
<test q="test2"></test>
</testdata>
user-extensions all-in-one (in the order as described above):
I got it directly from the SO link above.

Selenium IDE: Bind mouseOver() on dynamically generated div

i have a div element which is created via JS on the fly.
<div id='menu_item_0'>foo</div>
Now my Selenium IDE locator is able to access this element with various selectors, but whatever event like e.g. mouseOver or clickAt etc I use, they all seem to get ignored.
I could of course wirte some script an fire this, but i want to test exactly the mouseover by a mouse and not dispatch it by myself.
Anyone has an idea on this? The recorder does not record this too.
Thanks & Regards
Can you show us the complete html and js ?
Here's a test code I've run with success. Does it match what you're trying to do ?
The HTML :
<html>
<body>
<script>
function insert(){
var container = document.getElementById("container")
var newdiv = document.createElement('div');
newdiv.setAttribute('id','menu_item_0');
newdiv.innerHTML = 'Added the element';
newdiv.onmouseover = function(){
newdiv.innerHTML = 'I feel tickled';
}
newdiv.onclick = function() {
newdiv.innerHTML = 'I feel clicked';
}
container.appendChild(newdiv);
}
setTimeout(insert,2000);
</script>
<div id="container"></div>
</body>
</html>
And the selenium test (just save this in a .html file and open it from Selenium IDE) :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="file:///G:/dev/proj/test-selenium-ide/" />
<title>test1</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">test1</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>index.html</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>menu_item_0</td>
<td>2500</td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>menu_item_0</td>
<td></td>
</tr>
<tr>
<td>mouseOver</td>
<td>menu_item_0</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>menu_item_0</td>
<td>I feel tickled</td>
</tr>
<tr>
<td>clickAt</td>
<td>menu_item_0</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>menu_item_0</td>
<td>I feel clicked</td>
</tr>
</tbody></table>
</body>
</html>

Hudson + Selenium plugin - Getting HTTP error 403 when running tests

I am trying to test my application using Selenium tool via the Hudson plugin (the one called sleniumhq plugin).
As a proof of concept I decided to make a very simple test targetting google, the test is the one below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead>
<tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>3000</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>q</td>
<td>selenium rc</td>
</tr>
<tr>
<td>click</td>
<td>btnG</td>
<td></td>
</tr>
</tbody></table>
</body>
This test opens Google then searches for selenium rc.
When I run it using Hudson I get HTTP error 403 in the opened browser.
There is no specific error raised by Hudson or Selenium.
Here is my Hudson configuration:
browser : *iehta
startUrl : http://:4444/selenium-server/
suiteFile : suite.html (suite pointing to the test described before)
resultFile: result.html
other : -timeout 5 -debug -browserSideLog -ensureCleanSession -trustAllSSLCertificates
htmlSuiteRunner : C:\selenium\selenium-remote-control-1.0.1\selenium-server-1.0.1\selenium-server.jar
Do you guys have already faced such an issue? Is it linked to user rights definition or something?
Thanks in advance for your help!
I'm not familiar with Hudson, but that startUrl doesn't look right. Are you meant to have the IP address of the Selenium RC server in there? For example: http://10.100.1.1:4444
Also, if you are using the latest version of Selenium (1.0) then the browser should be set to '*iexplore' for Internet Explorer in HTA mode.