Read Until usage in robot framework with constant changing prompt - robotframework

I'm new to robot framework. I'm trying to create a Keyword in my suite to login to DUT, run a command and fetch the output. but the prompt of the DUT is constantly changing. Following is the keyword and also the command output in DUT.
Keyword snippet:
Write show table sys ClassOfService
${output}= Read Until Regexp admin#0-9 .*\>
command output in DUT:
admin#0-9 19:36:44> show table sys ClassOfService
profileXml "<?xml version=\"1.0\" encoding=\"UTF-8\"?><cos version=\"1.0\"> <PublicIdentifiers>
</PublicIdentifiers> \t\t\t </cos>";
[ok][2020-04-11 19:36:45]
admin#0-9 19:36:45>
But it is always getting timeout. Please let me know if I'm missing something.
Thanks in Advance

Your regular expression looks good, but in Robot Framework the > must have the \ escaped with another \. Look at the example for Read Until Regexp. Your final command should be:
Write show table sys ClassOfService
${output}= Read Until Regexp admin#0-9 .*\\>

Related

Informatica IPC - UNIX script fail

I have created a unix script to be executed after the session finished.
The script basically counts the lines of specific file and then creates a trailer with this specific structure:
T000014800000000000000000000000000000
T - for trailer
0000148 - number of lines
00000000000000000000000000000 - filler
I have tested the script in Mac, I know already that environments are totally different, but I want to know what is needed to be changed in order to execute this script successfully in IPC.
After execution I get the following error message:
The shell command failed with exit code 126.
I invoke the script as follows:
sh -c "$PMRootDir/scripts/exec_trailer_unix.sh $PMRootDir/TgtFiles"
#! /bin/sh
TgtFiles=$1
TgtFilesBody=$TgtFiles/body.txt
TgtFilesTrailer=$TgtFiles/trailer.txt
string1=$(sed -n '$=' $TgtFilesBody)
pad=$(printf '%0.1s' "0"{1..8})
padlength=8
string2='T'
string3=$(printf '%s%*.*s%s\n' "$string2" 0 $((padlength - ${#string1} - ${#string2} )) "$pad" "$string1")
string4='00000000000000000000000000000'
string5=$(printf '%s%*.*s%s\n' "$string3" 0 $((${#string3} - ${#string4} )) "$string4")
echo $string5 > $TgtFilesTrailer
Any idea would be great.
Thanks in advance.
Please check below points.
it looks like permission issue. Please login using informatica user(the user that runs infa demon) and run this command. You should be able to get the errors.
sh -c "$PMRootDir/scripts/exec_trailer_unix.sh $PMRootDir/TgtFiles"
Sometime the server variable $PMRootDir in UNIX doesnt get interpreted and can result null value. Please use echo $PMRootDir to check if its working after logging into UNIX using above user.
You can create trailer file using Infa easily.
Just add an aggregator transformation right before actual target( group by a dummy field to calculate count(*)). Then add an expression transformation to create those strings. And then trailer file target. Just 3 more transformations.
| --> AGG --> EXP --> Trailer Target file
Final Tr --|--> Final Target

Pytest failing on file open command string assert - what's the best way to test this?

I am constructing a command to pass to requests library to Post an attachment - as in
files= attachment = {"attachment": ("image.png", open("C:\tmp\sensor.png", "rb"), "image/png")}
The code is working but I cannot get PyTest to test it as -is because of the open command which is executed when evaluated. Here is simplified code of the problem
import pytest
def openfile():
cmd = {"cmd": open(r"C:\tmp\sensor.png")}
return cmd
def test_openfile():
cmd = openfile()
#assert str(cmd) == str({"cmd": open(r"C:\tmp\sensor.png")}) # this works
assert cmd == {"cmd": open(r"C:\tmp\sensor.png")} # this does not
PyTest complains that the two side are different but then confirms they are the same in the diff panel!
Expected :{'cmd': <_io.TextIOWrapper name='C:\tmp\sensor.png' mode='r' encoding='cp1252'>}
Actual :{'cmd': <_io.TextIOWrapper name='C:\tmp\sensor.png' mode='r' encoding='cp1252'>}
'Click to see difference' - Opening diff panel reports 'Contents are identical'!
I can just stick with comparing the generated string with expected string but am wondering if there is a better way to do this.
Ideas?
You need to test the properties of the actual file buffer that is returned by the open call, instead of the references to that buffer, for example:
def test_openfile():
cmd = openfile()
expected_filename = r"C:\tmp\sensor.png"
assert "cmd" in cmd
file_cmd = cmd["cmd"]
assert file_cmd.name == expected_filename
with open(expected_filename) as f:
contents = f.read()
assert file_cmd.read() == contents
Note that in a test you may not have the file contents, or have them in another place like a fixture, so testing the file contents may have to be adapted, or may not be needed, depending on what you want to test.
After talking this through with a friend I think my original approach is perfectly valid. For anyone that trips over this question here's why:
I am trying to pytest building of an executable parameter to pass to another library for execution. The execution of the parameter is not relevant, just that it is correctly formatted. The test is to compare what is generated with the expected parameter ( as if I typed it) .
Therefore casting to string or json and comparing is appropriate since that is what a human does to manually check the code!

How to fix "Escaping empty cells with '\' before line continuation marker '...' is deprecated" error in Robot Framework?

I keep on getting this error when running my Robot Framework script:
"Escaping empty cells with '\' before line continuation marker '...' is deprecated. Remove escaping before Robot Framework 3.2."
Here is a sample code:
*** Test Cases ***
Debug
${Str} = Set Variable Rose
: FOR ${Ctr} IN RANGE 1 5
\ Run Keyword If '${Str}' == 'Test' Log Test
\ ... ELSE Log Not Test
I searched for a solution and I only got this link: https://gerrit.openbmc-project.xyz/#/c/openbmc/openbmc-test-automation/+/22245/
I can see that they used FOR/END instead of :FOR (which was working fine before).
FOR ${userid} IN RANGE 2 16
${user_info}= Get User Info ${userid}
Run Keyword If "${user_info['user_name']}" != ""
... Run IPMI Standard Command user set name ${userid} ""
END
However, when I try to change my code to use FOR/END, RIDE automatically changes it back to :FOR.
I use RIDE heavily and would like to continue to do so I need it to work around this error. My RIDE is the latest one so upgrade won't work. Any help would be appreciated.
The syntax for the FOR-loop is changed. From the documentation:
Not closing loops with END, escaping keywords inside loops with \, and
using :FOR instead of FOR are all going to be deprecated in Robot
Framework 3.2. Users are advised to switch to the new syntax as soon
as possible.
With your code I can still run the test, but the deprecation warning is shown. To remove the warning this worked for me in Eclipse:
Debug
${Str} = Set Variable Rose
:FOR ${Ctr} IN RANGE 1 5
\ Run Keyword If '${Str}' == 'Test' Log Test
... ELSE Log Not Test
When you remove the escape character in the ELSE line the warning is no longer shown. This is a workaround though, untill a new version of RIDE comes along I guess.

expected at least 1 argument, got 0

I installed robot framework yesterday and trying to run a test file.Below is my test file, while i try to run the file using robot -d tests/Amazon.robot , i am getting a error as
[Error] Expected at least 1 argument,got 0.
can someone please help me.
You didn't specify where to look for tests and you are using -d incorrectly.
Most likely you need command robot tests/Amazon.robot
The problem looks like in the usage of the Sleep keyword - you want to pass the argument "3" to it, but did not put two or more spaces b/n them.
With problems like this, check the generated log.html file - the failure will be in the record for the specific keyword, helping you pinpoint which line is the error one.

Unix SQLLDR scipt gives 'Unexpected End of File' error

All, I am running the following script to load the data on to the Oracle Server using unix box and sqlldr. Earlier it gave me an error saying sqlldr: command not found. I added "SQLPLUS < EOF", it still gives me an error for unexpected end of file syntax error on line 12 but it is only 11 line of code. What seems to be the problem according to you.
#!/bin/bash
FILES='ls *.txt'
CTL='/blah/blah1/blah2/name/filename.ctl'
for f in $FILES
do
cat $CTL | sed "s/:FILE/$f/g" >$f.ctl
sqlplus ID/'PASSWORD'#SERVERNAME << EOF sqlldr SCHEMA_NAME/SCHEMA_PASSWORD control=$f.ctl data=$f EOF
done
sqlplus will never know what to do with the command sqlldr. They are two complementary cmd-line utilities for interfacing with Oracle DB.
Note NO sqlplus or EOF etc required to load data into a schema:
#!/bin/bash
#you dont want this FILES='ls *.txt'
CTL_PATH=/blah/blah1/blah2/name/'
CTL_FILE="$CTL_PATH/filename.ctl"
SCHEMA_NM=SCHEMA_NAME
SCHEMA_PSWD=SCHEMA_PASSWORD
for f in *.txt
do
# don't need cat! cat $CTL | sed "s/:FILE/$f/g" >"$f".ctl
sed "s/:FILE/$f/g" "$CTL_FILE" > "$CTL_PATH/$f.ctl"
#myBad sqlldr "$SCHEMA_NAME/$SCHEMA_PASSWORD" control="$CTL_PATH/$f.ctl" data="$f"
sqlldr $SCHEMA_USER/$SCHEMA_PASSWORD#$SERVER_NAME control="$CTL_PATH/$f.ctl" data="$f" rows=10000 direct=true errors=999
done
Without getting too philosophical, using assignments like FILES=$(ls *.txt) is a bad habit to get into. By contrast, for f in *.txt will deal correctly for files with odd characters in them (like spaces or other syntax breaking values). BUT the other habit you do want to get into is to quote all variable references (like $f), with dbl-quotes : "$f", OK? ;-) This is the otherside of protection for files with spaces etc embedded in them.
In the edit update, I've varibalized your CTL_PATH and CTL_FILE. I think I understand your intent, that you have 1 std CTL_FILE that you pass thru sed to create a table specific .ctl file (a good approach in my experience). Note that you don't need to use cat to send a file to sed, but your use to create a altered file via redirection (> $f.ctl) is very shell-like too.
In 2nd edit update, I looked here on S.O. and found an example sqlldr cmdline that has the correct syntax and have modified to work with your variable names.
To finish up,
A. Are you sure the Oracle Client package is installed on the machine
that you are running your script on?
B. Is the /path/to/oracle/client/tools/bin included in your working
$PATH?
C. try which sqlldr. If you don't get anything, either its not
installed or its not in the path.
D. If not installed, you'll have to get it installed.
E. Once installed, note the directory that contains the sqlldr cmd.
find / -name 'sqlldr*' will take a long time to run, but it will
print out the path you want to use.
F. Take the "path" part of what is returned (like
/opt/oracle/11.2/client/bin/ (but not the sqlldr at the end), and
edit script at 2nd line with
(Txt added to appease the S.O. Formatter ;-) )
export ORCL_PATH="/path/you/found/to/oracle/client"
export PATH="$ORCL_PATH:$PATH"
These steps should solve any remaining issues. If this doesn't work, see if there is someone where you work that understands your local computing environment that can help explain any missing or different steps.
IHTH

Resources