Not able to Import Selenium2Library in a robot file - robotframework

Below image is the sample reference of the robot code I have written. I have imported Selenium2Library, there were no errors but in test case section of Robot framework its not getting recognized.
Sample Robot Code
clearly, under settings section, we see that the library selenium2library is not being recognized?

I hope you have installed the "robotframework-selenium2library". if not, please use the following pip command
pip install robotframework-selenium2library
I have referred your image and I could see there is a syntax error while you import a library.
In Robot test file settings sections, while importing a library the syntax should be
Library YouDesiredLibrary
In this case it is
Library Selenium2Library
Once you are done with all the imports you have the define any variables you want to use for your test case which you have done correctly.
In the test cases Table/section
You need to call open the URL, you need to user Open Browser keyword with browser name and URL ans arguments
Please try this and let me know.

Related

RobotFramework RIDE cannot import library

I have a file right here: Library ../../MyLib/My_Lib.py, and I try to import the python file in RIDE, but RIDE still report "FAIL : No keyword with name '****' found", and this keyword is defined in the My_Lib.py, seems RIDE cannot find the python file.
I using python 2.7.8+Robot Framework 3.1.2+windows server 2012r2. I even selected Library -> Name -> Browse in RIDE, but the error still there and this whole robot test case folder is copied from another server which is working fine
Can anyone suggest what have I missed?
Ah! I have worked this out, if anyone else meets the same issue, you can click Tools->view RIDE Log, to see what's happening there. For my case, it's because I didn't install thrift but the My_Lib.py obviously used thrift module, so the My_Lib.py compile failed with "No module named thrift.Thrift".
Is it possible the Python library was created to work with Python 3.x.x leading it to not work on your Python 2.7.8? See https://wiki.python.org/moin/Python2orPython3
Check what python version is being run on the other server where the test is running fine. You might need to update your local Python version.
Also, you could try running the Robot test outside of RIDE just in case. You may do so by navigating to the test folder where the .robot file resides and running the following command:
robot test_file_name.robot
See if you get the same error that way. Please report back after doing the mentioned checks and we can continue debugging, my reputation doesn't let me comment on your question so I will just update the answer as we go along.

How to call python module in Robot framework

I do have the following folder structure for python scripts.
From Python I can run a script in folder Feed2Scripts as follows. Can this be possible in Robot Frame Work through imported libraries? > Note that I have common scripts in ‘GeneralScripts’ used by all other scripts in different folders
../Scripts>python –m Feed2Scripts.Script1 param1
If I just import Feed2Scripts/Script1.py as a library in RF, then It is failing to load libraries defined 'GeneralScripts'
First you set your python path on RIDE's Tools->Preferences->Importing Pythonpath so it does include your library and all its dependencies (imported modules and so on), like this:
(If your library is distributed via PIP, just pip install my_library_package_name instead, on the same environment you are running Robotframework/RIDE)
Then you can add the library to your test suite on the add library dialog you can open by pressing the library button on the Edit tab you can see when you select the suite:
After that, all keywords defined in your library will be available for use in any test of the test suite. You will see a Library import sentence on the Settings section of the header of your suite's code (On your text editor or RIDE's Text Edit tab of the suite:
Sometimes RIDE doesn't recognize the keywords on a recently added or modified library right away. In that case, Save all (CTRL+SHIFT+S) and restart RIDE to fix the issue.
Also, watch out for the library entry showing up in red on the suite import list on RIDE's Edit tab; it means something went wrong when trying to import the library. If you need to know what, you can find the trace on RIDE's Tools->View Ride Log.

Let atom editor recognize external APIs

I'm trying to set up a python like environment with Atom-editor on a Linux machine.
I find the autocomplete-python package that uses jedi.
In the settings of the package I tried to add some python path where the APIs are (/usr/lib/python2.7/dist-packages/) but then the autocompletion doesn't recognize these libraries (for example the PyQt ones)
Am I missing something?
For anybody having the same issue please look here.
Basically everything should work out of the box, but if it does not -- try to configure path to python executable with which you have installed your external module. If it's still fails to complete -- try to configure extra path to python modules. (usually your site-packages directory)

setup pythonpath before starting test suite

Currently I am setting pythonpath as pybot --pythonpath ~/Test_suite main.robot while running the tests.
I also see there is option Set Environment Variable PYTHONPATH ${CURDIR} to set through robot framework. But it doesn't run before main settings
*** Settings ***
Documentation Suite description
Resource settings.robot
And below is settings.robot file
*** Settings ***
Resource keywords/keywords_test.robot
Library tests.test_1.TestClass
How to setup the pythonpath before running the suite?
You can't do what you want. The settings are all processed before any test or keyword is run. You can use the --pythonpath option from the command line, or set the environment variable PYTHONPATH before starting your test.
You can do it by adding to sys.path in suite init.
E.g. you can create __init__.robot file in tests directory with:
*** Settings ***
Suite Setup Setup before all tests
*** Keywords ***
Setup before all tests
evaluate sys.path.append(os.path.join("path", "to", "library")) modules=os, sys
Described in official docs: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#configuring-sys-path-programmatically
I'm not sure if this would work, but I think there actually might be a way to do what you're talking about. It's pretty jenky, so bear with me.
You can't really do it in Robot Framework, but if you expand your horizons to Python, there's a neat little exploit I've found. If you take a look in other posts how to create a custom Python Library for Robot framework, you'll notice that there's a required method called __init__ with parameters of (self). I believe that this is the very first code to run when the Library instance is created. Little-known fact, you can add parameters to the creation of the Library instance. In your case, ~/Test_suite would be the value that you would pass.
IN THEORY, because I haven't tried this, you could tell __init__(self, path_in) to run your BuiltIn keyword with the following code:
self.BuiltIn().set_environment_variable('PYTHONPATH', path_in)
Don't forget to use the following import statement at the top of the file.
from robot.libraries.BuiltIn import BuiltIn

Unable to import DateTime library in Robot Framework

I want to use keywords written in DateTime Library
http://robotframework.googlecode.com/hg/doc/libraries/DateTime.html?r=2.8.5
I have robot framework 2.8.6.
Whenever I import this library in my tests in RIDE; it is shown in red (not resolved). Also in documentation I am not able to search the keywords.
Your problem is probably with RIDE and not Robot Framework. RIDE uses its own copy of RF regardless of what you have installed. The included version is out of date. Try copying DateTime.py from Robot Framework installation to the folder in RIDE.
For example, copy C:\apps\Python27\Lib\site-packages\robot\libraries\DateTime.py to
C:\apps\Python27\Lib\site-packages\robotide\lib\robot\libraries
Then restart RIDE.
ombre42 is right, RIDE (my current is 1.3.0) includes an older version of RobotFramework which does not includes DateTime module. You have the RobotFramework 2.8.6 installed, but you doesn't use it when you launch tests using RobotFramework-RIDE.
Two important things:
Copy DateTime.py from your RobotFramework 2.8.6 as ombre42 said, but don't import DateTime using pip: it will work but you'll not get the RobotFramework's one (which is better and documented).
When you run your tests outside of RIDE, in a Jenkins environment for example, you'll probably use the RobotFramework 2.8.6 (or later) and not the same as your RIDE environment.
I'm use RF with Python and by default my IDE sees Python DateTime library.
Use full path:
Library robot.libraries.DateTime

Resources