RIDE icon indicating copy to clipboard operation
RIDE copied to clipboard

Variable file rejected if it contains variables with a hyphen or space in the name

Open MarkAWalters opened this issue 5 years ago • 14 comments

This is my second attempt to use variable files, as I struggled to figure out why Ride would not accept my file. After some experimentation, it seems Ride does not like variables within a variable file to have hyphens (or spaces) in the name. This is confusing as it allows hyphens and spaces in variable names that are created elsewhere.
E.g. this code in a resources file works:-

 *** Variables ***
 ${ID-Prefix}

Also the documentation in RF (https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#variables) does not specifically warn against using hyphens (using only alphabetic characters from a to z, numbers, underscore and space is recommended...).

I am not sure if this is a RF or just a Ride issue, but I am hoping it can either be fixed, or the documentation updated to reflect the limitation.

Many thanks

MarkAWalters avatar Jun 10 '19 15:06 MarkAWalters

This is because RobotFramework allows you to do arithmetic operations inside the variable, for example ${counter+1}. Your hyphen is being interpreted as a minus sign. You're going to have this issue with all operators. Validating variables in RIDE isn't feasible in my opinion.

@HelioGuilherme66 What do you think?

Nyral avatar Jun 10 '19 16:06 Nyral

@MarkAWalters You mention variable files, but you show a variable without definition. Also when you say RIDE does not "accept my file", please detail the error you get. It would be nice to have some testable examples, and compare with robot execution.

HelioGuilherme66 avatar Jun 10 '19 18:06 HelioGuilherme66

Thanks for the responses guys.

@Nyral Yes, the hyphen can cause problems if you later try to do arithmetic operations inside the variable, so I am moving away from using the hyphen, but as mentioned it is valid elsewhere plus the documentation does not exclude this usage, but old habits die hard, plus other users can experience the same issues. However, besides any short term solutions, it possibly raises the question of whether the use of hyphens in variable names should be deprecated in the longer term.

@HelioGuilherme66 The example was taken from the variable list within Ride (which I assume is the 'variable table' referred to in other articles), to show that that syntax including a hyphen is valid there, (I use that variable as a suite variable which is assigned a value in test setup, which is why it had no initial value).

The error I get is simply that the library is highlighted in red, there is no other error message.

Examples of the problem variables are as follows:

 LOC-campaignCode	= '#campaign_code'
 LOC-Campaign name	= '#campaign_name'
 LOC-Company name	= '#company_name'    

If I replace the hyphens with underscores and remove the spaces (in the variable names), the file name is displayed in black.

Thanks

Mark

MarkAWalters avatar Jun 11 '19 07:06 MarkAWalters

@Nyral - sorry if I seem a bit slow, but I'm not sure why you labelled this as not-a-bug?

MarkAWalters avatar Jun 19 '19 07:06 MarkAWalters

@MarkAWalters If you run the test case from command line with robot would it work? Probably not because python variables must not have spaces in their name.

HelioGuilherme66 avatar Jun 19 '19 09:06 HelioGuilherme66

Thanks again gentlemen.

@HelioGuilherme66, I can try this but a bit later, I haven't tried running from the command line at all yet although I do want to get there, but right now I'm exploring the use of resource and variable files and still need to get work done, so it might take a few weeks before I can try this out.

Once I have the results of that test, should I transfer this to the robotframework/robotframework repository?

Thanks

Mark

MarkAWalters avatar Jun 20 '19 13:06 MarkAWalters

@Nyral - sorry if I seem a bit slow, but I'm not sure why you labelled this as not-a-bug?

Because it's a RobotFramework issue, not a RIDE issue.

Once I have the results of that test, should I transfer this to the robotframework/robotframework repository?

You can, it could be documented better. The reason it isn't is because they must be valid python variables if they're inside a variable file. That's just how it works.

Nyral avatar Jun 21 '19 00:06 Nyral

Hi

On second thoughts, it probably isn't worth testing this from the command line, I'm sure Helio is quite correct in saying it won't work.

To move this forward, we have two possible actions:

  1. Improve Robot documentation (RobotFrameworkUserGuide.htm).
  2. Upgrade the RIDE error processing to provide a more informative message.

The reason I say this is that there are surely many other Robot and RIDE users who are not Python developers (like myself at this stage), and who are therefore unaware that the Python variable naming rules are different from Robot's.

  1. Improve documentation - I have the following wording suggestion (my words in italics, the rest is existing text for context) - what is the process for doing this?

2.8.2 Variable files Variable files contain variables that can be used in the test data. Variables can also be created using variable tables or set from the command line, but variable files allow creating them dynamically and their variables can contain any objects.

Variable files are typically implemented as Python modules and there are two different approaches for creating variables:

Note: Python variable names have different rules to those applicable in Robot Framework (and by implication RIDE). Specifically, hyphens and spaces are not allowed, thus names like MY-VAR = 'my value' or MY VAR = 'my value' will both cause a problem.

Creating variables directly Variables are specified as module...


  1. Upgrade the RIDE error handling - at present the only error indication is that the entry in RIDE is highlighted in red - no other error message or info is displayed either in RIDE or the Windows command prompt:

RIDE: image

Windows Command Prompt:

     C:\Users\markw>ride.py

     DevTools listening on ws://127.0.0.1:51712/devtools/browser/5f6b9262-248a-4543-8d05-fb4d976cd232

It would be really helpful if some informative error message was displayed in RIDE.

Thanks

Mark

MarkAWalters avatar Jun 21 '19 09:06 MarkAWalters

OK. Your suggestions are valid. But user should know or try to investigate why the Variables file import is in red. If you see the Tools->RIDE Log, there should be there the python import error (if not then that is a Bug in RIDE).

HelioGuilherme66 avatar Jun 24 '19 10:06 HelioGuilherme66

Closing because is too old and we cannot reproduce, or lack of information.

HelioGuilherme66 avatar Dec 01 '19 19:12 HelioGuilherme66

I'm not sure why this has been closed, I can reproduce it at will, so the issue still exists, and I thought there was sufficient information in the various comments above.

If more information is needed, please give me the specifics of what you need.

Thanks

On Sun, Dec 1, 2019 at 9:48 PM Hélio Guilherme [email protected] wrote:

Closing because is too old and we cannot reproduce, or lack of information.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/robotframework/RIDE/issues/1945?email_source=notifications&email_token=AMF7MTZIFIP5LA4XXJGWGATQWQIIFA5CNFSM4HWULV52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFRTSJI#issuecomment-560150821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMF7MTYS7KPSHFDXORDUSP3QWQIIFANCNFSM4HWULV5Q .

LOC-inactive-Users = "CSS:#inactive-users-link" LOC-users-Message = "CSS:#users-message" LOC-users-Table = "CSS:#users-table > tbody .form-check" LOC-reactivate-Selected = "CSS:#reactivateSelected > span"

MarkAWalters avatar Dec 05 '19 08:12 MarkAWalters

@MarkAWalters You can:

  • Go to Robotframework project and post your documentation change proposal (usually forking the project and modifying the document and creating a Pull Request (PR)).
  • Using the example variables python file, causing the red color on the import, look at Tools>RIDE Log to see if there are errors. Those errors should indicate the invalid content on the variable file.

HelioGuilherme66 avatar Dec 05 '19 10:12 HelioGuilherme66

@HelioGuilherme66

  • Ah, so that's how I raise a documentation change proposal - thanks, I'll try to do that a bit later when I have time to play around (still a bit of an idiot in githgub).
  • I checked my log as suggested, no errors are shown, just some (old) info messages as follows:

20191127 17:35:03.598 [INFO]: Found Robot Framework version 3.1.1 from 'C:\Python27\lib\site-packages\robot'.

20191127 17:35:03.599 [INFO]: Started RIDE 1.5.2.1 using python version 2.7.12 with wx version 2.8.12.1 in win32.

Since RIDE can be temperamental, I closed and reopened it, but still shows just the info messages..

MarkAWalters avatar Dec 05 '19 11:12 MarkAWalters

@MarkAWalters So RIDE Log does not show any error. We can see the Python error when we Run the test. Here is an example:


[ ERROR ] Error in file 'D:\Testes\test_import_vars.robot': Processing variable file 'D:\Testes\failed_vars.py' failed: Importing variable file 'D:\Testes\failed_vars.py' failed: SyntaxError: can't assign to operator (failed_vars.py, line 2)
Traceback (most recent call last):
  None
PYTHONPATH:
  C:\Program Files\Python37\Scripts\robot.exe
  c:\program files\python37\python37.zip
  c:\program files\python37\DLLs
  c:\program files\python37\lib
  c:\program files\python37
  C:\Users\USER\AppData\Roaming\Python\Python37\site-packages
  c:\program files\python37\lib\site-packages
  c:\program files\python37\lib\site-packages\win32
  c:\program files\python37\lib\site-packages\win32\lib
  c:\program files\python37\lib\site-packages\Pythonwin
  c:\program files\python37\lib\site-packages\wxPython-4.0.5
  C:\Program Files\Python37\lib\site-packages\robotide\contrib\testrunner\../../lib

I'll consider to improve RIDE (but we have many other fixes and improvements before this one ;) )

HelioGuilherme66 avatar Dec 05 '19 13:12 HelioGuilherme66