Robot Framework and SeleniumLibrary Simple Example - selenium

*** Settings ***
Library SeleniumLibrary
Suite Set Up Start Selenium Server
Suite Tear Down Stop Selenium Server
*** Test Cases ***
Opening
Open browser http://www.bbcnews.com googlechrome
I am using above code to run simple robot frame work script with selenium.. What am i doing wrong ?? It is stuck at opening.. but doesn't open anything browser..

The biggest problem is that you're using very old technology: the most recent release of SeleniumLibrary is from 2012. You should be using Selenium2Library rather than SeleniumLibrary.
From the SeleniumLibrary project page:
According to http://seleniumhq.org, the old Remote Controller API is
officially deprecated in favor of the new WebDriver API. As a result
also SeleniumLibrary is deprecated and no new releases are expected.
New users should use the already mentioned Selenium2Library and
existing users should start to plan migrating to it.
Here's an example of a working test (in pipe-separated format)
*** Variables ***
| ${BROWSER} | chrome
*** Settings ***
| Library | Selenium2Library
| Suite Teardown | Close all browsers
*** Test Cases ***
| Example
| | Open browser | http://bbcnews.com | ${BROWSER}
By using a variable for the browser, you can run against any browser by using a command line argument. For example, to run with firefox you can do:
pybot --variable BROWSER:firefox myTest.robot
Note that drivers for chrome and ie need to be downloaded and installed separately.

Related

How to override chrome setting to download pdf instead of opening in new tab with selenium robot framework

I am currently using the following code where ${BASE_URL} is my system under test and ${BROWSER} value is set to chrome. I have followed the solution provided on the thread: click here
But somehow disabling the Chrome PDF Viewer is not working. I am still seeing PDFs are being opened in new tab instead of downloaded to local directory.
*** Settings ***
Documentation Common setup and teardown steps
Library SeleniumLibrary
Resource UtilManager.robot
*** Keywords ***
Begin Test
[Arguments] ${BROWSER} ${BASE_URL}
#{workingDirs} UtilManager.Get Current Working Directories
${chrome options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
log ${chrome_options}
# list of plugins to disable. disabling PDF Viewer is necessary so that PDFs are saved rather than displayed
${disabled} create list Chrome PDF Viewer
${prefs} create dictionary download.default_directory=${workingDirs}[1] plugins.plugins_disabled=${disabled}
call method ${chrome options} add_experimental_option prefs ${prefs}
create webdriver ${BROWSER} chrome_options=${chrome options}
go to ${BASE_URL}
maximize browser window

How to pass multiple arguments to a test case in CumulusCI test automation framework?

Problem statement:
Unable to pass multiple variable values to my test case using CumulusCI command:
`cci task run robot...
I am referring this section for building my command: https://cumulusci.readthedocs.io/en/latest/tasks.html#id49
If I have to pass just one variable in the same way as above, say for eg. just LocalOrRemote, then the code works perfectly fine, so it appears that this has to do something with the way I am passing multiple variables.
My test automation tech stack is Robot Framework, CumulusCI, Selenium
Sample Code:
*** Settings ***
Resource C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Suite Setup Run Keywords Suite Setup KW1 AND Suite Setup OS And Browser ${LocalOrRemote} ${Browser}
*** Test Cases ***
Verify whether I am able to set environment and browser
[Tags] LocalEdge
[Documentation] This test should run on the local edge browser
Keyword X
Keyword Y
*** Keywords ***
Suite Setup KW1
do something
Suite Setup OS And Browser
[Arguments] ${LocalOrRemote} ${Browser}
Log Many ${LocalOrRemote} ${Browser}
run keyword if '${LocalOrRemote}'=='Local' Setup Local Browser ${Browser}
... ELSE IF '${LocalOrRemote}'=='Remote' Setup Remote Browser ${Browser}
... ELSE FAIL "Incorrect environment value passed! Please refer the instructions in README for running the test suite"
Command I am using to invoke my test:
cci task run robot -o suites mypath/MyTestFile.robot -o include LocalEdge -o vars LocalOrRemote:Local,Browser:edge
Issue I am facing:
The value of ${Browser} is not received as edge but defaulted to chrome, which means the command is not able to pass on my desired value to the TC.
KEYWORD BuiltIn . Log Many ${LocalOrRemote}, ${Browser}
Documentation:
Logs the given messages as separate entries using the INFO level.
Start / End / Elapsed: 20190522 16:36:53.877 / 20190522 16:36:53.878 / 00:00:00.001
16:36:53.877 INFO Local
16:36:53.877 INFO chrome
How to pass multiple arguments to a test case in CumulusCI test automation framework?
The way you are doing it is the correct way: -o vars var1:value1,var2:value2
Here's a really simple example:
*** Test cases ***
Example
Should be equal ${LocalOrRemote} Local
Should be equal ${Browser} edge
Save that to a file and then run it with the robot task like this:
cci task run robot -o vars LocalOrRemote:Local,Browser:edge -o suites example.robot
You will see that the variables are initialized properly. If the wrong browser is opening up, one of your libraries must be changing the value of the ${Browser} variable without you realizing it.
Thanks a ton #Bryan for the direction. It was that moment when you get so awestruck by your own creation and forget to try out basic debugging in your framework.
Anyway, the issue here was the placement of resources as you rightly pointed out. Observe the before and after code pieces below. The issue (well at this point I cannot comment that its an issue or shortcoming) revolves around the placement of Salesforce.robot resource. For the Cci command to pass the right value of the 2nd variable, I had to place this resource in the test case itself. The Cci command did not pass the right value of the 2nd variable when I had this resource loaded via an environment file; weird.
*** Settings ***
Documentation ###My setup before:
Resource C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Suite Setup Run Keywords Suite Setup KW1 AND Suite Setup OS And Browser ${LocalOrRemote} ${Browser}
Documentation ###My setup after:
Resource C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
Resource cumulusci/robotframework/Salesforce.robot #had to place this resource here
Suite Setup Run Keywords Suite Setup KW1 AND Suite Setup OS And Browser ${LocalOrRemote} ${Browser}
*** Test Cases ***
Verify whether I am able to set environment and browser
[Tags] LocalEdge
[Documentation] This test should run on the local edge browser
Log "TC passed"
My setup before:
C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
*** Keywords ***
Suite Setup KW1
Import Resource cumulusci/robotframework/Salesforce.robot #the resource that was causing the issue
Import Resource C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
import resource C:/Dev/myproject/robotframework/ValidationKeywords.robot
Import Library cumulusci.robotframework.CumulusCI ${ORG}
import library SeleniumLibrary timeout=7 seconds implicit_wait=5 seconds
import library OperatingSystem
import library BuiltIn
C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
*** Keywords ***
Suite Setup OS And Browser
[Arguments] ${LocalOrRemote} ${Browser}
Log Many ${LocalOrRemote} ${Browser} #used to default Browser value passed to chrome
`
My setup after:
C:/Dev/myproject/robotframework/EnvironmentSetupFile.robot
*** Keywords ***
Suite Setup KW1
#Import Resource cumulusci/robotframework/Salesforce.robot # had to comment this resource here and place it before the Suite Setup
Import Resource C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
import resource C:/Dev/myproject/robotframework/ValidationKeywords.robot
Import Library cumulusci.robotframework.CumulusCI ${ORG}
import library SeleniumLibrary timeout=7 seconds implicit_wait=5 seconds
import library OperatingSystem
import library BuiltIn
C:/Dev/myproject/robotframework/BrowserSetupKeywords.robot
*** Keywords ***
Suite Setup OS And Browser
[Arguments] ${LocalOrRemote} ${Browser}
Log Many ${LocalOrRemote} ${Browser} #now returns the correct Browser value

How to declare global base url on RIDE in robot framework

On RIDE editor there are 5-6 test suites. Each test suite opens the same URL after opening browser. I want to use a global variable (base URL )for those test suite. Could you please help me how to do it. Thanks in advance.
[]
You will need to delcare it as global by using
*** Variables ***
#{url} Set Global Variable www.google.com
*** Test Cases ***
test1
log to console ${url}
it's BuiltIn's Library.

Running Robot Tests with Phantom JS

Can someone please tell how to run Robot Tests with Phantom JS?
I have written few Robot tests. I was able to run successfully with different browsers (ie, ff, Chrome).
I want the same to run with Phantom JS (Headless browser). For this, I gave 'phantomjs' for "browser" argument just like below (sample robot script).
*** Settings ***
Library C:/python27/lib/site-packages/Selenium2Library
*** Test Cases ***
Test
Open Browser http://example.com phantomjs
Log Source INFO
But getting below error.
WebDriverException: Message: 'Unable to start phantomjs with
ghostdriver.' ; Screenshot: available via screen
Someone please help me in this.
Make sure you have PhantomJS executable downloaded and added into PATH. I use the below method specifically to handle the PhantomJS browser to open:
Create Webdriver PhantomJS
Go To http://account.netzero.net
I'm sure it will work if you have the PhantomJS in the PATH env.

Selenium Webdriver - How to use Robot Framework with Java

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