selenium rc server does not exit after running an htmlsuite - selenium

Am I missing something obvious? The docos state that:
-htmlSuite : Run a
single HTML Selenese (Selenium Core) suite and then exit
immediately ...
but my instance doesn't seem to (it also doesn't write to the html output either)
I am running : java -jar /opt/selenium-server-1.0.3/selenium-server.jar -debug -htmlSuite *googlechrome http://www.google.co.uk ~/tsg1.ts ~/g.out
I have also given up trying to put xml into this editor - but all I am doing is opening www.google.co.uk and looking for "about google" - which works fine in the firefox ide, but never exits on RC... Any ideas ?! The same happens with *firefox as well :-(

Ok - I dug around and found the following.
The selenium IDE generates an ERRONEOUS line in the "heading" which somehow breaks the -htmlsuite option (ie it never exits). Comment the line out as per this example :
`
< table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium" >
< tbody >
< !-- < tr >< td >< b > Test Suite< / b >< /td >< /tr > -- >
< tr >< td >< a href="test_case_google" >test_case_google< /a >< /td >< /tr >
< /tbody >< /table >
< /body >
< /html >
`

Try with quotes:
java -jar /opt/selenium-server-1.0.3/selenium-server.jar -debug -htmlSuite '*googlechrome" "http://www.google.co.uk" "~/tsg1.ts" "~/g.out"

I only have this problem with firefox. Running with chrome seems to work fine.
If you do what Richard Green suggests you only get to run one test (the last one it seems). The "Test Suite" line tells selenium that it is a test suite and needs to run all the tests present.
So the problem seems to be that in firefox at least it wont jump from test to test when running a test suite.
For firefox if you do what is described in this issue: https://code.google.com/p/selenium/issues/detail?id=1759 it works. Chrome works too.
If by any chance the link doesn't work the workaround is to remove the first two lines of the files:
... yanked out the first two lines of each file. The ones starting with:
xml version...
DOCTYPE html PUBLIC...

You "must" save all your html test with ".html" extension and reference them in testSuit.html with the ".html" extension.
So, instead of:
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium">
<tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td>test_case_google</td></tr>
</tbody>
</table>
It "must" be:
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium">
<tbody>
<tr><td><b>Test Suite</b></td></tr>
<tr><td>test_case_google</td></tr>
</tbody>
</table>

Related

Codeception tests randomly fails on redirects using click

I've got weird problem with failing codeception test.
Sometimes click method used on link/button doesn't redirect to page.
sometimes it does, but codeceptions doesn't recognize it (I see on image in output that redirect worked).
And sometimes its perfectly okay, and test runs at 100%.
I use codeception 2.2.1 version with phantomjs 2.1.1 on jenkins.
One of problematic tests:
$I->wantTo('verify that recent comments module are correctly presented');
$I->amOnPage('/pl/');
$I->click('.cookie-policy-info__btn-close');
$I->see('Najciekawsze opinie', '.section-title-bar');
$I->seeElement('.hp-recent-opinions.one-column-product-wrapper');
$I->seeElement('ul.slides:nth-child(1) > li > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-
$I->click('ul.slides:nth-child(1) > li > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child
$I->seeInCurrentUrl('/audiobook/');
$I->moveBack(1);
$I->click('ul.slides:nth-child(1) > li > div.product-tile > div.product-tile__desc > div.product-tile__author
$I->seeInCurrentUrl('/search/author?');
$I->moveBack(1);
Example of $this->titleCss() = 'ul.slides:nth-child(1) > li > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)'
and codeception output:
5) ContentModulesCest: Verify that recent comments module are correctly presented
Test tests/acceptance/ContentModulesCest.php:recentCommentsModule
Step See in current url "/foobar/"
Fail Failed asserting that '/pl/' contains "/foobar/".
Scenario Steps:
8. $I->seeInCurrentUrl("/foobar/")
7. $I->click("ul.slides:nth-child(1) > li > div:n...")
6. $I->seeElement("ul.slides:nth-child(1) > li > div:n...")
5. $I->seeElement(".hp-recent-opinions.one-column-prod...")
4. $I->see("Najciekawsze opinie",".section-title-bar")
And on image I see that page. It's weird.
Any ideas how to stop that random fails?
Possibly when Codeception tries to click, that element is invisible(not loaded yet). Try to use waitForElementVisible method before click method.
Also it could be connected with PhantomJS version. I have a plenty of weird problems with that - anything is possible.

Find string from javascript code with selenium IDE

I´m testing web page and i need to assert code fragment in javascript code, such as
<script type="text/javascript" src="//img.xxxx.com/u/14/p42449.js"></script>
<script type="text/javascript">
window.ptag_params = {
zone: "homepage",
customerId: "Your customer ID",
siteType: "Site Type",
};
</script>
I´ve tried use
<tr>
<td>verifyHtmlSource</td>
<td>*42449*</td>
<td></td>
</tr>
but I don´t see any response, in log only
[info] Executing: |verifyHtmlSource | *42449* | |
What am i doing wrong???
The selenium command you've used there isn't really the best for what you're trying to do. All that will do is check that somewhere within the entire html of the page, the number 42449 appears, doesn't guarantee it will find it in the script fragment you want to see it in. in regards to the logs, you won't see any more output than you have in the log with a verify command because it will just pass or fail depending on if it finds that number.
If you need to confirm this element exists and would like to see some output containing it in the logs your best bet would be a combination of verifyelement and storelement Example below
Script
<tr>
<td>verifyAttribute</td>
<td>css=script#src</td>
<td>*42449.js</td>
</tr>
<tr>
<td>storeAttribute</td>
<td>css=script#src</td>
<td>source</td>
</tr>
<tr>
<td>echo</td>
<td>${source}</td>
<td></td>
</tr>
Log Output
[info] Playing test case Untitled
[info] Executing: |verifyAttribute | css=script#src | *42449.js |
[info] Executing: |storeAttribute | css=script#src | source |
[info] Executing: |echo | ${source} | |
[info] echo: //img.xxxx.com/u/14/p42449.js
[info] Test case passed
The only thing you'd need to be careful with is if you have multiple script tags on your page, you'd just need to amend the locator with an nth value if it's the second or third script etc.
Finally, i´ve used
<tr>
<td>storeHtmlSource</td>
<td>buscaPixelesVen</td>
<td></td>
</tr>
<tr>
<td>verifyEval</td>
<td>javascript{storedVars['buscaPixelesVen'].indexOf("42449",0)>0}</td>
<td>true</td>
</tr>
and it works. Maybe is not the best solution, but is enough.
Thanks in any case
Code above looks good but since it's not based on css it shouldn't matter with order.
<tr>
<td>verifyElementPresent</td>
<td>//script[contains(#src, 'p42449.js')]</td>
<td>*ga.js</td>
</tr>
<tr>
<td>storeAttribute</td>
<td>//script[contains(#src, 'p42449.js')]#src</td>
<td>source</td>
</tr>
<tr>
<td>echo</td>
<td>${source}</td>
<td></td>
</tr>

Selenium - Store iframe:src

I have a webpage which contains an iframe such as this
<iframe src="iframe_src" style="border: none" scrolling="no" id="id_frame" width="100%" frameborder="0" height="1850">...</iframe>
I'm trying to storeText the iframe src attribute, but executing the following command won't do the trick:
storeText //iframe[#id='id_frame']//#src frame_src
I expect frame_src to be equal to "iframe_src"
How can I do it?
Thanks!
I expect frame_src to be equal to "iframe_src"
First off, storeText will store the innerHTML of your target. What you want, is the storeAttribute command, however we can simplify it using the verifyAttribute command.
Command | Target | Value
============================================================
verifyAttribute | //iframe[#id='id_frame']#src | frame_src

How to increase/decrease the sleep time in clickAndWait command in selenium IDE?

Command : clickAndWait
Target : some xpath of the location
After executing this command in selenium IDE, it takes huge time to load the data into the page. So in the Log of IDE, I could see as 'Timed out after 30000ms'.
Is it possible to increase/decrease the value 30000ms ?
Command Target Value
click id=ext-gen007
waitForPageToLoad 60000 wait for one minute
click id=ext-gen008
waitForPageToLoad 60000 wait for one minute
click id=ext-gen009
waitForPageToLoad 60000 wait for one minute
I'm using Selenium IDE 1.8.1 , After editing as above it gives an error as 'Timed out after 60000ms'
In Selenium2 / Webdriver you have to use setTimeout(long milliseconds)
With Selenium you have to use:
<tr>
<td>setTimeout</td>
<td>60000</td>
<td>Wait 60 seconds for the page</td>
</tr>
See setTimeout ( timeout ) in Selenium Reference
Also take a look at waitForPageToLoad ( timeout )
<tr>
<td>click</td>
<td>Your XPath</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>60000</td>
<td>Wait one minute</td>
</tr>

Using GREP / RegEx to find and replace string

So, I'm trying to migrate a database from Textpattern CMS to something more generic. There are some textpattern-specific commands inside of articles that pull in images. I want to turn these into generic HTML image links. At the moment, they look like this in the sql file:
<txp:upm_image image_id="4" form="dose" />
I want to turn these into something more like this:
<img src="4.jpg" class="dose" />
I've had some luck with TextWrangler doing some regex stuff, but I'm stumped. Any ideas on how to find & replace all of these image paths?
EDIT:
For future reference, here's what I ended up doing in PHP to output it:
$body = $post['Body_html'];
$pattern = '/txp:upm_image image_id="([0-9]+)" form="([^"]*)"/i';
$replacement = 'img src="/images/$1.jpg" class="$2"';
$body = preg_replace($pattern, $replacement, $body);
// outputed <img src="/images/59.jpg" class="dose" />
I wouldn't use grep; it's sed you want
$ echo '<txp:upm_image image_id="4" form="dose" />' | sed -e 's/^.*image_id="\([[:digit:]]*\)".*form="\([[:alpha:]]*\)".*/<img src="\1.jpg" class="\2" \/>/'
<img src="4.jpg" class="dose" />
$
if your class has alphanumeric characters, use [[:alnum:]]
(works on macos darwin)
Not sure which tool you are using but try this regex solution: Search for this:
<txp:upm_image\s+image_id="(\d+)"\s+form="([^"]*)"\s*\/>
And replace with this:
<img src="$1.jpg" class="$2" />
Note that this only works for txp tags having the same form as your example. It will fail if there are txp tags having extra attributes, or if they are in a different order.