Open ac57486 opened 3 years ago
Hi,
Regarding 1: the transitive imports are supported by RED. I'm not sure if I understand this correctly but it seems that the file of unknown name visible at your first screenshot does not import CommonImport.robot
, so RED do not see the keywords/variables defined by this file or imported by this file. How do you attach this file when you launch the first file? Is the first file only a resource file or a tests suite?
Login To Sfc
is defined. This may likely not work if for some reason RED is not able to properly recognize this library. Actually this should have the same effect as if you would find Sfc_Common
library in project explorer, then the Login To Sfc
keyword and clicked Show keyword source
from context menu like here:
is it possible for you?FIRST ISSUE: This is how a flow goes --> Test (here CommonImports.robot is added)--> Step Definition (step declared in Tests is defined here) --> Keyword Definitions in Python Library (Keyword definitions, eg Open Browser Maximized) I will add screenshots one by one to show where CommonImports.robot has been added:
Test : Here Test case is written which is Chat.robot file. We import CommonImport.robot here so that it is available for test and step definitions
Step Definitions: Here the step written in Test case is defined which is GeneralActions.robot
The below screenshot shows the Common variables files which is available globally. This ${browser} variable also shows error if you refer above screenshot
Keyword Definitions: : Here Keywords written in step definitions are defined. e.g. Open Browser Maximized
SECOND ISSUE : I could see Open Definition for Login To Sfc kyword and also I am able to open this keyword by clicking F3 or doing ctrl+click. But when I debug, I am unable to open this keyword:
Hi,
Any update on above issues?
Hi,
sorry I had no time to look into that further. I'll try to do it today.
I would like to add one more point here for SECOND ISSUE i.e. Click here works if the library is in the same project(i.e. sfctests) but if it is in other project(for my case libraries are in sfctools) then Click Here is not working. PFA
@michalanglart could you please help me here? It's been 14 days I have been waiting for the reply
Hi,
sorry for the delay but I was on a leave of absence. Additionally the team is now 2 out of 5 members couple of weeks ago + we're busy with other work assigned.
Anyway:
about the ${browser} variable: have you looked in here: https://nokia.github.io/RED/help/user_guide/project_config/variable_files.html ? I'm assuming you're adding the variables file when running tests via --variablefile/-V
option, right? You can add this file to red.xml and RED will see those variables in all the files inside this project.
I now do understand your case with unrecognized keywords. You seem to have a setup like this:
tests.robot
*** Settings ***
Resource common.robot
Resource other.robot
*** Test Cases ***
test
${x}= keyword
Log ${x}
common.robot
*** Keywords ***
keyword
${date}= Get Current Date
[Return] ${date}
other.robot
*** Settings ***
Library DateTime
RED in this case will mark Get Current Date
keyword as unrecognized although if you would run tests.robot
everything would run and the date would be printed. We do know about this behavior of Robot Framework although we were rather surprised when we found out a year ago or so. At the time it wasn't even documented as far as I remember (I don't know if it is now) and I remember talking to Pekka Klärck about this.
When RED is doing analysis of common.robot
it does not know where Get Current Date
is defined because there are no imports in this file. This is very slippery because what if you would create another file:
tests2.robot
*** Settings ***
Resource common.robot
*** Test Cases ***
test
${x}= keyword
Log ${x}
Now you would have an error when trying to run it. So what now should RED do? Should it mark as error or not? Or should it make even more complicated analysis and instead of error show a warning telling that: "This Get Current Date
is fine when you import the file from tests.robot
but would be an error when imported from tests2.robot
"? We've decided to leave it as it is, so RED is seeing the keywords/variables from the files/libraries which are imported by this file or by other imported files (transitively). It however does not handle that kind of dependencies like in the example.
IMO apart from confusing IDE this case may also confuse other developers when reading the code even in some notepad - he/she may likely run into a question: "why does this keyword is used if the file I'm looking at does not import another where the keyword is defined? How does it work?".
@michalanglart Thank you for the detailed explanation for issue 1 and 2.
Here is my sample code for point 3. I have two projects SampleTests and SampleTools. Here I would like to highlight one point i.e. The two projects could interact with each other with the help of python packaging and importing the libraries into the SampleTests project using relative path I have kept the test case and step definition in SampleTests, whereas, in SampleTools, I have defined the keywords used in step definition. eg. I have keyword "Login To Sfc" in step definition in SampleTests as given below:
SampleTests
Settings Variables SFC/PageObjects/Component/Sfc_QuickLinkComp.py Library SFC/Libraries/Sfc_Common.py
Keywords Login to application Login To Sfc ${user_profile}
Here, if you see Library, this is how I have imported Sfc_Common.py Library using relative path of the project. This library is created in SampleTools project. Hence the keyword "Login To Sfc" is defined in Sfc_Common.py library.
SampleTools:
@keyword def login_to_sfc(user_profile=None): sl = BuiltIn().get_library_instance('SeleniumLibrary') sl = BuiltIn().get_library_instance('SeleniumLibrary') sl.input_text(sfc_tbx_user_name, username) sl.input_text(sfc_tbx_password, password) click_element_using_javascript(sfc_btn_login)
PFA for the same, so that the explanation given above could be understood better:
SampleTests:
Please refer the highlighted parts:
SampleTools:
Please refer the highlighted parts:
Please let me know in case of any confusion
- Here, my understanding is, the error that comes for such keywords which are not directly imported is the expected behavior by RED. Is my understanding correct?
Partly. As I said RED supports and will support recognizing keywords/variables which are imported transitively (so you have a.robot
which imports b.robot
which imports lib
and RED will recognize keywords from lib
inside first file although strictly speaking this library is not imported by a.robot
). On the other hand we are not willing to support this awkward type of dependencies where a.robot
is importing both b.robot
and lib
while b.robot
imports nothing but Robot is able to recognize keywords from lib
used inside b.robot
.
As to the code you've placed here - I'll try to take a look today or tommorow. But just for now: those project does not seem to be configured as RED project, do they? If that's the case this may be the cause of not being able to click the keyword hyperlink. Can you configure the projects which have Robot code as RED projects (available from context menu Robot Framework -> Add Robot nature
https://nokia.github.io/RED/help/user_guide/project_config/red_xml_overview.html)
Thanks for the clarification. As per the above project that was only a sample project I shared so that I could explain you the two projects. In my real project I have red.xml.
Regarding global variable files, I followed the approach suggested by you and added Variable files to red.xml, still that error persists. I followed the link shared. Is there any additional setting required to remove the red error? I have copied the screenshot for the same:
red.xml snapshot with Variable files:
.robot file with error:
Just to confirm:
red.xml
is in the same project as the .robot
file with ${browser}
?red.xml
?This is the one of the variable file env.py from where we are taking ${browser} variable. I have imported this into red.xml as variable files. So will this file be considered as variable file? I have observed error comes only for this browser variable imported from this file, variables imported from other variable files does not give error.
Here argument arg is passed from additional robot framework arguments as given below:
Lets check it:
vars.py
browser = 'chrome'
def get_variables(arg=None):
return {'var' : 'value'}
suite.robot
*** Test Cases ***
test
Log ${var}
Log ${browser}
Lets run it:
python -m robot.run --variablefile vars.py suite.robot
and we have:
test | FAIL |
Variable '${browser}' not found.
but ${var}
was found and logged properly. So the answer is: yes it is a valid variables file, but only variables returned by get_variables
function are available for Robot in this case. That's why RED also does not see it.
You would need to move your browser
variable into the map returned by the function if you want to see it.
Also as a side note: you can add some completely dummy variable file into red.xml - it is used just for purpose of validation or content assistance.
In the past (like 2 years ago or so) the files specified in red.xml were also added into command line argument --variablefile
when running the tests from the project within RED, but then we have introduced possibility to define Default launch configuration so if someone wanted to have some file added whenever running the tests it was better to use it, additionally it created some problems with ovverriding variables when they were both in default launch configuration and in red.xml so we've removed this possibility and now:
browser = 'xyz'
vars = '123'
as the values does not matter at all in this context.
Actually, you have tried using ${browser} like this:
browser = 'chrome'
def get_variables(arg=None): return {'var' : 'value'}
That is why robot is not identifying it.
Could you please try like this:
browser = 'chrome'
def get_variables(arg=None): return {'browser' : browser}
Now robot will identify the ${browser} variable but Red would not. This is the way I am using ${browser} in my case.
Sorry I've missed your reply. Actually the file like this:
browser = 'chrome'
def get_variables(arg=None):
return {'var' : 'value', 'browser' : browser}
does work for me and RED can see both ${var}
and ${browser}
Hello,
I am facing two problems with imports and debugging customized python libraries(user created python libraries):
1) I have some keywords that are defined in customized Python libraries. e.g. 'Open Browser Maximized' which takes 3 arguments and is defined in the python library created by me which is Selenium.py
Please refer screenshot:
2) Another problem is, When I am debugging user python code, I could see screen to Click here (please refer screenshot) while debugging using pydev. Bur when I click on "Click Here", it does nothing and remains on the same page. But if I debug the build in Python libraries provided by robot, it takes me inside that Python Library but fail to do so into user created Python Libaries. May I know how to fix this debugging issue?