Selenium Webdriver - How to use Robot Framework with Java - selenium

I want to use robot framework with java in Eclipse IDE. i have installed robot framework in Eclipse IDE. How to write script by using robot framework with Selenium web-driver.

If you want to use eclipse as an IDE to write your tests you can use this plugin:
RobotFramework-EclipseIDE
If your goal is to write a java method then call it from robotframework you can use Remote library.
Here are the supported formats writing robotium tests:
Robotium Test Data Sytntax
You can also use maven to run robotframework test from maven project in eclipse:
Robotframework Maven plugin

If you want to write user defined keywords in java which can be used in robot script, import "AnnotationLibrary".
Link is mentioned below and follow the steps AnnotationLibrary
.

try this way.
i am using python language to write test case. python is best way to write a test cases.
my test case file name is test_google_page.robot put this code to test_google_page.robot file and save it. next open command line and go to test_google_page.robot file path and run this command
[user#localhost google_test]$ pybot test_google_page.robot
then you can seen your test case result.
*** Settings ***
Documentation your document
Library Selenium2Library
*** Variables ***
${Url} https://www.google.lk
${Browser} chrome
${Delay} 3s
*** Test Cases ***
load google page
[Documentation] your test case document
OPEN BROWSER ${Url} ${Browser}
Input text id=lst-ib robot framework
sleep ${Delay}
# click button id=<button_id>
# Page Should Contain loglevel=INFO text=<content>
Capture Page Screenshot filename=test_result.png
[Teardown] CLOSE BROWSER

Related

Export test case as - Java / JUnit /Webdriver using latest Selenium IDE

Is there an option to export the tests as "Java / JUnit /Webdriver" or 'Enable Webdriver Playback' option using latest Selenium IDE? I added this extension to my Firefox browser and I don't find these options. It actually saves the file as testName.side format. When I open this file in EclipseIDE, it is actually in a JSON format.
I have a requirement where I need to quickly navigate through all the links across multiple pages and I thought SeleniumIDE will be the best option where I can use the 'Enable Webdriver Playback' option and run it in all the browsers.
Any thoughts on this?
Here is the link to the Selenium IDE documentation SeleniumIDE_Documentation
At the time you asked the question it was probably not possible with Selenium IDE 3.
But now you can right click on a test-name in the test list, and select the option to 'Export' it to a Java JUnit test.
Please ensure that the 'mode' of the IDE (below the project name) is set to 'Tests' and not 'Executing' when you perform the right click.
See more information in the documentation

Running selenium test cases(Test cases are in robot framework) using jenkins

I have test cases which i have written in robot framework. I have written one library for robot framework but it all for selenium. I am using firefox browser. This test cases are working fine if i am running through command line.
If I start test cases using jenkins this error will show. I am using shell command to start robot framework.
NoSuchElementException: Message: Unable to locate element: {"method":"link text","selector":"Config Box"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
When running tests with Jenkins there are different timings on when the elements are available. Try to use keywords of Wait For ... or Sleep.

Running Selenium tests in Jenkins

I have recorded some simple selenium tests by Selenium IDE. Now I want to run those tests in Jenkins.
Which plugin to Jenkins do I need to do that? And how to run the tests step by step? Help is appreciated.
you can use recorded selenium IDE script and selenium-server.jar file to run it from Jenkins
Here is steps:
Go to SeleniumHQ page and download Selenium Server file
Eg: selenium-server-standalone-2.33.0.jar
Repair html test suite Use Selenium IDE to record then save as
html test case and test suite then put them in a same folder
eg: TestCase.html, TestSuite.html
In jenkins
Plugin Seleniumhq
Configure Selenium runner file
Manage Jenkins > Configure System > Selenium Remote Control: htmlSuite Runner = path to file u have download in step 1
Configure Job to run
In Build field click " Add build step" then select "seleniumhq htmlSuite Run"
browser: *firefox or *iexploer ....
startURL: http://www.google.com or ...
suiteFile: Input absolutely path to TestSuite.html file saved in step 2
resultFile: Input absolutely path to a file that results will be saved
Hope this help!
I did the same but the following error occurred:
Unable to find the HTML runner. This is normally because you have not downloaded
or made available the 'selenium-leg-rc' jar on the CLASSPATH. Your test will
not be run.
Download the Selenium HTML Runner from http://www.seleniumhq.org/download/ and
use that in place of the selenium-server-standalone.jar for the simplest way of
running your HTML suite.

play auto-test selenium test failed, no test-result TEST-{testname}.xml file generated

We have a Play (1.2.4) application which is auto-tested via our Teamcity server. The regular (JUnit) tests return a Test-{classname}.xml datafile in the /test-result/ directory when using
play.bat auto-test
but the selenium tests do not. They only generate a /test-result/{testname}.test.html.failed.html or ...succes.html
This is annoying because i can not easily show which selenium test has failed from within Teamcity. I have to look at the logfiles/artifacts and see which failed.html file is present, open it and look at it which testcase has failed. Annoying!
How can i have play 1.2.4 generate a datafile/xml something which i can parse to see which selenium test has failed?
Since i could find no information what so ever and no clue's how to get it done i wrote my own parsers of the Selenium HTML testresult files. I have released it on github with sourcecode under GPL: https://github.com/crunchie84/play-seleniumresults-parser

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.