Selenium user-extensions, Selenium IDE - selenium

I use Selenium IDE.I needed if-else construction and I found a Javascript file. I used the file in IDE easily. However when I tried to use the file with Selenium RC, I followed the steps:
Opened selenium.jar file and changed the user-extensions file(this file is in core->scripts->user-extensions) with what I found(which includes if-else functions) from internet.
I started selenium rc with the command:
-java -jar selenium.jar -userExtensions user-extensions.js
-htmlSuite "*chrome" "linkofsite" "staj\Projects\SikayetTestleri.html" "result2.html" -port 4445
Selenium server started firefox but nothings happend...

I've found another way to solve my problem.Instead of user-extensions I used storeEval command and wrote 2 lines of javascript code.I used conditional statement instead of if statement.
Selenium IDE command:
<tr>
<td>storeEval</td>
<td>
selenium.isElementPresent('Element I control')?selenium.doClick('Element which will be clicked if the element present'):seleniumdoClick('Element which will be clicked if the element NOT present')
</td>
</tr>

Related

Selenium IDE - waitForTextPresent

I have a problem with Selenium IDE's command - waitForTextPresent.
<tr>
<td>waitForTextPresent</td>
<td>*saved successfully</td>
<td></td>
</tr>
I had a couple of tests which are using this command. All tests worked fine, but now, during executing this command web application freeze, after while Firefox crashed, whole Firefox freezed and i received from Selenium IDE timeout exception after a while. So my question is, why is it happening?
I didn't change tests or selenium settings.
One time I received error:
A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.
Script: chrome://selenium-ide/content/…nium-core/scripts/htmlutils.js:679
Windows 7
Firefox 38.0.5
Selenium IDE: 2.8.0
I am using couple of add-ons related to Selenium (e.g.: Sel Block).
waitForTextPresent is a deprecated command, try using just waitForText with a CSS locator as the target, and the '*saved successfully' bit as the value.
Update:
You can use XPath for detecting the contained text as well For example:
waitForElementPresent | //*[#id="objectid" and contains(text(),"Text You Want")]
Older solution with waitForText:
You have to use WaitFortext
waitForText | Locator | Textpattern
for example
waitForText | //* | *saved successfully
asterisk can be used on beginning, middle or end of the text pattern

Selenium RC got stuck at "Checking resource aliases"

I am new to selenium, I got a problem when running selenium RC.
Actually, I have recorded one script via selenium IDE and saved it as test.html and I am able to run the script via selenium IDE but when I try to run the script via selenium RC it gets stuck at some point and displays the following message in the console "Checking resource aliases"
command for running the script via command prompt:
java -jar selenium-server.jar -htmlSuite "*firefox" "www.google.com" "test.html" -port 4445
Let me know the exact reason why this happens?
You should save your tests as a Test Suite also.
At the end you will have two HTML files, the Test Suite and the Test Case (or more if you want).
The command java -jar .... to run selenium, with the -htmlSuite parameter, takes an HTML Test Suite, not a Test Case.
I had the same problem and after passing the Test Suite as the parameter worked as charm.
Step-1: Please create a new html file TestSuite.html
<html>
<head>
<title>My Application Test Suite</title>
</head>
<body>
<table>
<tr><td><b>Suite Of Tests</b></td></tr>
<tr><td>Test Example</td></tr>
</table>
</body>
Step-2: Rename OPSTest.html to your file name test.html.
Step-3: Run this command in command line
java -jar selenium-server.jar -htmlSuite "*firefox" "www.google.com" "TestSuite.html" -port 4445

selenium rc storeEval not working across tests

the storeEval command works across test cases within a suite when using the selenium IDE -- (firefox addon)
but the same suite does not work when using the selenium RC (jar)
The variable is not stored
Example
test1
click
storeEval "asd" foo
test2
type element_id ${foo}
"asd" appears in selenium IDE. However, "foo" appears" in selenium RC
Any suggestions?
Thank you
PS: Please note this is an htmlsuite running in both selenium IDE & selenium RC
I found the solutionby editing one of the jar files:
http://mumblblog.wordpress.com/2011/10/19/make-store-command-work-with-selenium-rc-to-pass-values-between-test-cases/
about editing the file inside jar:
How can I edit a .jar file?
It helped for me.

selenium RC and Flow control

Currently I am working on selenium IDE, now I need to switch to selenium RC. I have downloaded selenium server.But I really don't know how to proceed further. Even I am not able to start server from command prompt. I have used C:\Selenium RC\selenium-server\jave -jar selenium-server.jar, but it struck in between and not proceeding further..
I am looking for language java or PHP.
Let me know how should I move further for successful execution of scripts by using selenium RC
First of all: save a test suite in Selenium IDE (File > Save Test Suite). You should generate test suite - it will contain information about test cases (which, of course, should also be saved (File > Save Test Case)).
Then you are ready for testing with Selenium RC.
Try it with below command:
java -jar path/to/selenium-server-standalone.jar -htmlsuite "*firefox" "http://google.com" "path/to/your/testsuite1" "path/to/result.html"
result.html - this file will be generated during/after execution.
Be sure that name of browser, URL and paths to test suite and result file are in the quotation marks.
I am using Selenium with PHPUnit. I have got class called, lets say, somethingTest (test classes must have 'Test' at the end of their names) and extended PHPUnit_Extensions_SeleniumTestCase. This class contains several test cases as methods (e.g. function testSomeMethod1() - 'test' at the beginning).
And I run it by command:
phpunit somethingTest.php
As to the second thing:
Unknown command: gotoIf
You should load gotoif extension by adding to the execution command something like: -userExtensions path/to/extension-file
This indicates a JavaScript file that will be loaded into Selenium.
If you choose Java to write code, a better approach would be using an IDE like Eclipse. Once you link the JARs and import them in your Java classes you can write your code quickly and efficiently. On top of that, Ecplise has lot of plugins for testing software like Junit, TestNG's to help you create better test suites. Not to mention a Java IDE is always helpful in debugging test code. Here is a tutorial on how to setup Eclipse with Selenium: http://selftechy.com/2011/05/31/setting-up-selenium-with-eclipse
Hope it helps.

I want to run Selenium test case file from command line

I made then saved a test case with the Firefox extension "Selenium IDE".
Now I want to use command line to run this exported html file.
I try to follow this how-do-i-launch-the-selenium-ide-from-the-command-line-with-a-specific-test-case but it doesn't work.
Please help me.
You will need the Selenium RC which you can get from:
http://seleniumhq.org/download/
And Java 1.5 or higher (Download Java here)
1) Install Java
2) Unpack Selenium RC.
3) Open a cmd.exe window and go to the directory containing the Selenium Server (selenium-remote-control-1.0.1\selenium-server-1.0.1)
4) Run the command below:
java -jar selenium-server.jar -htmlSuite "*firefox" "http://10.8.100.106" "C:\mytestsuite\mytestsuite.html" "C:\mytestsuite\results.html"
This should run your test suite in Firefox and write the results to the html file. Obviously you will need to change the "http://10.8.100.106" argument to your own server (this might just be localhost / 127.0.0.1)
It is possible to run individual test cases using Selenese Runner. You can specify a single test case file or a test suite as the unit to run.
We should execute the SeleniumRC in using following command;
java -jar filename.jar
ex:
java -jar program1.jar
the program1 consist of the followings are:
program1.class file
Resource library file such as SeleniumRC Server.jar and Selenium Java client.jar file
This method is applicable for SeleniumRC execution. We can directly create the program1.jar file from eclipse using
File->Export.
Here is an article that explains you step-by-step process of how to run Selenium RC application in Java.
Create a Java Selenium RC test script and executing the script
I have needed to do this before, and used the following:
An Ant Build (complex)
Creating a test runner class(a part of junit framework)class.
Most commonly we would run into build path errors while trying to run from cmd.
If you want to run it from command prompt you may consider writing your selenium test in python.
Make sure you have python installed if you are on windows. Mac will have python by default.
Running test from CMD is quite easy.
Follow below steps
1- Go to home directory and Set class path
Home Directory > set classpath=Home Directory\bin; and press enter
Home Directory > set classpath=Home Directory\lib*; and press enter
2-Home-directory > java org,testng.TestNG testng.xml testng2.xml testng2.xml and hit enter
I have documented all steps here. Hope it will help. Cheers
1) Running from CMD
java -cp "C:\ProjectX\Mortgage\bin;C:\Selenium_latest\selenium2.49.1\*;C:\Selenium_latest\selenium-2.49.1\libs\*" org.testng.TestNG C:\ProjectX\Mortgage\testng.xml
Run above command in C:\ProjectX\Mortgage
2) Create batch file name runner.bat
SET projectLocation=C:\ProjectX\Mortgage
CD %projectLocation%
SET classpath=%projectLocation%\bin;C:\Selenium_latest\selenium-2.49.1\*;C:\Selenium_latest\selenium-2.49.1\libs\*
java org.testng.TestNG %projectLocation%\testng.xml
PAUSE
3) Run the batch file by double clicking on it.
To be able to run in Chrome browser, you can use *chrome option instead of *firefox like below
java -jar selenium-server.jar -htmlSuite "*chrome" "http://localhost" "C:\testsuite\testsuite.html" "C:\testsuite\results.html"
Other browsers list include:
*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom
on session null