Read variable name from file and use as locator variable - robotframework

I have a file with locators which I import in my test suite. The file has lines like these:
LOCATOR_ABC='id=abc'
LOCATOR_XYX='id=xyz'
I have another file which contains locator variable names and expected values, so something like this:
LOCATOR_ABC¤hello world
LOCATOR_XYZ¤goodbye world
Now I want to loop through the latter file and do something like this for each line:
${locator}= Fetch From Left ${line} ¤
${value}= Fetch From Right ${line} ¤
${ui_value}= Get Text ${${locator}}
... compare value and ui_value and expect them to match ....
The problem is I get the error:
Variable '${?LOCATOR_ABC}' not found. Did you mean:
${LOCATOR_ABC}
I know the part with ${${locator}} is probably not nice/correct, but changing my setup so the locator¤value file has lines like this:
${LOCATOR_ABC}¤hello world
${LOCATOR_XYZ}¤goodbye world
And then use this in my test instead:
${ui_value}= Get Text ${locator}
The error message is:
ValueError: Element locator '?${LOCATOR_ABC}' did not match any elements.
So I guess my question is if anyone can shed some light on the ? part of the error message? What am I doing wrong? And or is there another/better way to do this?

Problem with file encoding. Changing to ascii encoding solved the problem.

Related

Why does contents of ^FN1 in ZPL not show all content when used in ^BQ command with ^FD?

I am looking for some direction here, as I seem to be missing something. I have the following ZPL that is loaded into a ZD620:
^XA
^LH0,0^LRN^FT100,50,0^A0N,30,30^FN1^FDCORELIMS.BARCODE^FS
^FO471,27^BQN,1,3^FDQA,^FN1^FS
^FT381,188^A0N,50,68^FD^FN1^FS
^XZ
I use an off-the-shelf software that turns CORELIMS.BARCODE into the entity's barcode value to be encoded. That works fine. What is not happening, when the Generated QR Code is scanned, the output is always missing the first 3 characters. What should show up is something like: 5BX10, what I get is: 10.
During my troubleshooting I used the following code and I receive the full string:
^XA
^LH0,0^LRN^FT100,50,0^A0N,30,30^FN1^FDCORELIMS.BARCODE^FS
^FO471,27^BQN,1,3^FDQA,5BX10^FS
^FT381,188^A0N,50,68^FD^FN1^FS
^XZ
All other fields using the ^FN1 command (including this one: ^FT381,188^A0N,50,68^FD^FN1^FS) output the correct value, just not the generated QR code.
I found similar questions, however, none of which are using a ^FN command, and their suggestions do not work for my situation. Those links are listed here:
Print ZPLII QR to open url
ZPL QR code not printing what is in the string
Thanks for help and I would really like to learn what I am doing wrong.
The ^FNx commands are used with stored formats; they cannot be used in a "one-off" label format like you are showing. I am traveling and don't have a zebra printer to test this but basically you need to define the label format "template" using ^DF like:
^XA
^DFR:MYFORMAT.ZPL^FS
^LH0,0^LRN^FT100,50,0^A0N,30,30
^FO471,27^BQN,1,3^FN1^FS
^FT381,188^A0N,50,68^FN1^FS
^XZ
That stores the format as R:MYFORMAT.ZPL. Then you use ^XF to recall the format and provide the values for the ^FNx:
^XA
^XFR:MYFORMAT.ZPL^FS
^FN1^FDQA,CORELIMS.BARCODE^FS
^XZ
Note that you include the extra data params required by ^BQ in the ^FD string.
Hope that helps.

Finding word in PDF

I would like to find some word after convert PDF.
1)I have 2 PDF at path C:\TRM\PDF 1.pdf and 2.pdf
1.pdf has word "ICG00058"
2.pdf has word "ICG00065"
2) Convert Pdf To Txt at ${detail_1} already.
3) Suppose, I don't know the word in 1.pdf and I want to check that
1.pdf has ICG00058 or ICG00065.
I'm so sorry,If the question is not clear.
Please investigate this issue for me cause It's paramount important for my work.
*** Settings ***
Library Selenium2Library
Library String
Library Pdf2TextLibrary
*** Test Cases ***
Read PDF
${detail_1} Convert Pdf To Txt C:\\TRM\\PDF\\1.pdf
LOG ${detail_1}
${ID_1} Get Regexp Matches ${detail_1} ICG00058
${ID_2} Get Regexp Matches ${detail_1} ICG00065
Run Keyword And Ignore Error $ID_1[0] in $detail_1 LOG ${ID_1}
Run Keyword If $ID_2[0] in $detail_1 LOG ${ID_2}
ERROR:
Evaluating expression 'RF_VAR_ID_2 [0 ]in RF_VAR_detail_2' failed: IndexError: list index out of range
I used pdfgrep just like grep you can search for regex expressions in the pdf without any intermediate step.
I used it to look up ISBN numbers in the pdfs and automatically rename the filename to include the found ISBNs or write the filename and ISBN to an MySQL database.
If you don’t know how to write regex there are some online tools to test regex online until you find the right one to use.
You need to call the Evaluate keyword if you want to run python within your robot script, that is why you are seeing the error you have mentioned.
In your case though you could use the Get Index From List and List Should Contain Value keywords:
${matched_id_1}= Get Index From List ${ID_1} 0
Run Keyword And Ignore Error List Should Contain Value ${detail_1} ${matched_id_1}
${matched_id_2}= Get Index From List ${ID_2} 0
Run Keyword And Ignore Error List Should Contain Value ${detail_1} ${matched_id_2}
If you want to use the List Should Contain Value keywords as assertions just remove the Run Keyword And Ignore Error keywords in the answer

In Robot Frame Work How Can we use value returned from one keyword as input argument to other keyword directly(without use of variable)

How Can we use value returned from one keyword as input argument to other keyword directly (without assigning return value to variable)
Currently I am maintaining all Web Elements or Variable names and corresponding xpath in an Excel Sheet. I get XPath using keyword read_xpath by passing web element/variable name as argument.
I store the xpath in separate variable then make use of it for other or Next line keyword. Since I need to use a variable for each XPath access, i am trying to find out, whether is there any way to directly use one keyword output as input to other keyword without assigning it to variable.
The main purpose of storing XPath in Excel sheet is to avoid multiple test cases change with single Element XPath change, making just single change on Excel Sheet should be sufficient.
For Example:
read_xpath reads values from a Excel sheet, Excel sheet has two columns, one variable name and second one is xpath. Function read_xpath(element) takes variable name as input and gives back xpath.
xlread.py file looks like xlread.py code Excel Sheet look like Excel sheet
sample.robot file looks as below
${login_user_textctrl}= read_xpath username_textctrl
clear element text ${login_user_textctrl}
Input text ${login_user_textctrl} admin
Now let us check how I used read_xpath keyword in my robot file
I called Keyword read_xpath with argument username_texctrl, which returns xpath for username text Control which is stored in variable ${login_user_textctrl}. Now Input Text ${login_user_textctrl} admin works fine.
For below code
clear element text read_xpath username_textctrl
I am getting, clear element text requires 1 argument but two arguments provided, is there any way i can use the the value returned from Keyword(read_xpath) as input to other keyword directly, without assigning it to any variable?
Thanks in advance.
Separating your locators from your robot code through an Object Repository is often done when the locators are reused a lot. An alternative implementation paradigm is to use the Page Object Model. An example of such an implementation can be found in the Robotframework-PageObjectLibrary.
In case you still prefer the Object Repository approach, then using the Selenium2Library keyword Add Location Strategy might be of interest to you. Below is a working example which uses a YAML file as it's OR to fetch the search input box and search button from Google.
ObjectRepo.yaml
OR:
searchbox: '//input[#id="lst-ib"]'
searchbutton: '//button[#id="_fZl"]'
Robot Script
*** Settings ***
Library Selenium2Library
Variables ObjectRepo.yaml
*** Test Cases ***
Yaml Object Repository
[Setup] Add Location Strategy yro Yaml Locator Strategy
Open Browser http://www.google.com Chrome
Input Text yro=searchbox Robot Framework
Click Element yro=searchbutton
Sleep 3s
[Teardown] Close All Browsers
*** Keywords ***
Yaml Locator Strategy
[Arguments] ${browser} ${criteria} ${tag} ${constraints}
${xpath}= Set Variable ${OR.${criteria}}
${retVal}= Get Webelement xpath=${xpath}
[Return] ${retVal}
As you can see the abstraction through a custom locator keyword allows for clearner code and not require you to fetch into a variable for later reuse.
You can use Evaluate to call python functions directly. Example:
${my element to clear}= Evaluate read_xpath("username_textctrl") xlread
See the documentation here
(Note: Example is untested and you should check if xlread is in PYTHONPATH, or found at test run time)

R Project Import Error

I'm brand new to R Project.
I've tried to import using the file path, and no matter what path way I use I get this same error. It says the back slash and the first character after it is an unrecognized escape.
I can import files by using the file.choose() function and manually navigating to my file, but I need to be able to use the file path method in code so that I can run multiple iterative steps without having to be there to choose the file at every point.
Does anyone have any ideals on why this error might occur? Is there anything wrong with my code? Is there some kind of configuration I need to do?
Thanks.
Data1 <- read.table(file="\Head-Location-001\MarketingAnalysis\Competitive Intelligence\Stick Rate\Last week\Test.cvs" sep",", header=TRUE)
Error: '\C' is an unrecognized escape in character string starting ""\fknp-sfs-001\fknmktanlys\
Import Error
replace all the \ with \\.
it's trying to escape the next character in this case the C so to insert a \ you need to insert an escaped \ which is \\
or
Replacing them with / works as well

Error while bootstrapping cloudify nodecellar example on localhost using virtualenv

executing bootstrap validation
Invalid input:
inputs.yaml. inputs must represent a dictionary.
Valid values can either be a path to a YAML file, a string formatted as YAML or a string formatted as key1=value1;key2=value2
How to solve this problem??
Since there are a lot of missing details in your question, I'll try to explain what could be the answer:
You didn't give the right path to the input.yaml file.
The path could be relative to your working directory, or a full path, but either way it must lead to the file.
Your input file is not formatted correctly.
An input.yaml file should include a dictionary of keys and values as in: image: 'redhat_santiago'. Tabs are not allowed, only spaces. All keys should be aligned to the same column.
Please try to check the above, in the future it would be better if you add the input file and the command you are using.
Best,
Jonathan

Resources