Robot framework - generate random data - python

I have a problem with generating the random string in robot. I am very new in robot and really dont know how to figure it out..
I found some solutions here and I tried to follow then, but I am doing something wrong obviously..
I got this error message in console: No keyword with name '${random_string} = Generate Random String' found.
My test case:
*** Settings ***
Library String
Resource resource.robot
*** Test Cases ***
Add New Project
${random_string} = Generate Random String 12 [LOWER]
Fill In Project Mandatory Fields ${random_string} descriptiondunno
Verify Added Project
[Teardown] Close Browser
In the resource file I have defined the keywords I am using in test:
Fill In Project Mandatory Fields
[Arguments] ${random_string} ${description}
Wait Until Element Is Visible ${PROJECT TITLE}
Input Text ${PROJECT TITLE} ${random_string}
and also:
Verify Added Project
[Arguments] ${random_string}
Click Element ${PROJECTS}
Table Should Contain ${GRID} ${random_string}
I really appreciate any help, because I am really lost in this now :(
Thanks!

What are you using as a separator? Just spaces? If so, maybe increase to using four spaces to clearly separate things
Based on the error it seems to think
${random_string} = Generate Random String 12 [LOWER]
is a keyword, this is not what you want, you only want it to consider Generate Random String a keyword.
Try the below and let us know what happens:
${random_string}= Generate Random String 12 [LOWER]

Related

How do i get the nth element from the list in robotframework

I am trying to log the Nth (i.e 3rd item) item in a list i have. I get the list by looping over an array of web elements. My code is as follows:
check order of list
#{list}= Get WebElements xpath://*[#id="demo-tabpane-list"]/div
FOR ${elements} IN #{list}
${text}= Get Text ${elements}
Log To Console ${text}
END
Now it logs all the text in the loop perfectly but i cant seem to get it to work if i try to log #{list} i get the following message:
[<selenium.webdriver.remote.webelement.WebElement (session="1f34fac642dd44bb02f0c2b5c9a84c6f", element="245f8875-f545-4037-83c6-eef1600bc285")>]
help is welcome!
How do i get the nth element from the list in robotframework
To get the nth element of a list, do it pretty much the same as you do in python:
*** Variables ***
#{list} one two three four
*** Test Cases ***
Example
Should be equal ${list}[2] three
This is described in the robot framework user guide in a section titled Accessing list and dictionary variables
I fixed it by importing the string library. And changing my code to:
[arguments] #{list}
FOR ${elements} IN #{list}
${text}= Get Text ${elements}
#{numberList}= Split String ${text} \n
${Lenght}= Get length ${numberList}
Should be equal ${numberList}[0] One
Should be equal ${numberList}[8] Nine
END
I split the text into loose elements that get put into an array so i can read them by index.

robot framework selenium How to retrieve a key from a diccionary

Recently I am attempting doing automation test in python with selenium-robot framework in two different browsers, but I am having an error when i try log the Alias of a Browser. The error says: "Dictionary '#{alias}' has no key '1'".
The code is this on:
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${url} http://google.com
${browser} chrome
*** Test Cases ***
TC to demostrate Browser Operation Keywords in Robot Framework
[Documentation] TC to demostrate Browser Operation Keywords in Robot Framework
Open Browser http://google.com Chrome alias=ChromeRCV
Maximize Browser Window
Open Browser about:blank ff alias=RCVFF
&{alias} Get Browser Aliases
Log #{alias}[1]
#{browser_ID} Get Browser Ids
Log #{browser_ID}[1]
Switch Browser 1
Input Text //*[#id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input RCVAcademy
Sleep 4s
Switch Browser #{alias}[1]
Go To http://salesforce.com
Close All Browsers
This is due to how Robot interprets the variables. Since you have written #{alias}[1] Robot assumes that the value on index 1 of list alias is also a list. To avoid this issue in future, think first what you want to get out from the variable before assigning the $, # or &. You can see better explanation in the Robot Framework User Guide.
Consider the below example
&{DICT}= {"key1": "value1", "key2": "value2"}
# Get a list of keys
#{KEYS}= #{DICT.keys}
# ==> #{KEYS}= ["key1", "key2]
# Get a value from dictionary
${VALUE}= ${DICT}[key1]
# ==> ${VALUE}= value1
# Get a value from list
${VALUE}= ${LIST}[0]
# ==> ${VALUE}= key1
As you can see, only when returning a list value, are we using the # sign. This is because whenever using the # sign, Robot will interpret the given value as a list of multiple values and attempt to pass each value separately - This is also why normally lists are passed with $ as arguments to make Robot pass them as single variable instead of multiple separate values.
Additionally you are attempting to return a value from a dictionary with a list-like index. This will not work that way - You'll either have to access the value based on the key or then as a list of keys or values.
Since you only need the key to access the browser with the alias, you might as well simply use the following
Log ${aliases.keys()}[1]
# or to log everything in the dictionary
Log ${aliases}
It appears you have misunderstood the return value of the Get Browser Aliases - it returns a dict where the key is the alias you have given to an instance, and the value is the index.
Thus when you have typed [1] you are targeting the alias 1 (integer), but that's not one of the aliases you've set - and thus it's not a key in that dictionary, and thus - the error you got.
Change to this - the "ChromeRCV" is an alias you actually have, and it should work:
Log #{alias}['ChromeRCV']

How to programmatically write a while loop in Robot Framework 4.0?

Scenario - I have a file with x number of alphabets (a, b, c, d, e, f).
I want to take this alphabets and write it into a list or a dictionary. The file can end at any alphabet but the loop must stop if it has picked up the last alphabet and there is no other alphabets.
Each alphabet must be captured individually and appended to the list/dictionary and not using variables like what is the length of file as we don't know this and it will always change.
Run loop until file is empty and add the contents into a list/dictionary. The dictionary can be as {1:a,2:b,3:c,4....}.
Maybe a case of using Exit For Loop If?
There is no while loop in the framework. What you can do is the following:
If this is file.txt:
a,b,c,d,e,f
This is how you could read each letter and put it into a dictionary.
Read the file as whole.
Split it based on the structure of the file.
Loop through the list got by the splitting.
*** Settings ***
Library OperatingSystem
Library Collections
*** Test Cases ***
Test
&{dict}= Create Dictionary
${key}= Evaluate 0
${file}= Get File file.txt
${splitted}= Evaluate """${file}""".split(',')
FOR ${letter} IN #{splitted}
${key}= Evaluate ${key} + 1
Set To Dictionary ${dict} ${key} ${letter}
END
Log ${dict}
As for a web example it depends on the application but here is a general approach. This test will open Stack Overflow and get all questions then log everything about them. It will only fetch the first page but you could loop (FOR) through all pages similarly.
Define a locator that would match all "records".
Get a list of records by using the Get WebElements keyword.
Loop through the list and apply logic.
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Web Example
Open Browser https://stackoverflow.com/questions Headless Firefox
${questions}= Get WebElements //*[starts-with(#id, "question-summary-")]
FOR ${q} IN #{questions}
Log ${q.text}
END
[Teardown] Close Browser

Maya Python, Renaming joints: more than one object matches name

Ok, so I get two errors whenever I try to run this script: but before I get ahead of myself: lets get to my objective.
create two joint chains, names are unimportant: but essentially I know that you can use brackets to list and isolate joint chains with matching children names. Instead my script seems to be ignoring the brackets and giving me the error anyways. I've tried every different flag for list relatives: but all that seems to do is change the error to something else.
I know that if this script was properly working it would only work on one joint chain because of the hardcoded names: but the script I'm pulling it from has name prefexes tied to the GUI to avoid hardcoding and allow adaptive naming: I'm only using the hardcoded as an example for this script. My complaint is this script doesn't work on ANY joint chain because I keep getting the error "more than one object matches name."
To run the script,save the following code as a .py in your maya documents script folder, restart your copy of maya, then open a new python tab and run the first three lines of code above import maya.cmds
'''
import exampleScriptTemplate
reload (exampleScriptTemplate)
exampleScriptTemplate.gui()
'''
import maya.cmds as cmds
if cmds.window("buildWin", exists =True):
cmds.deleteUI("buildWin", window = True)
myWindow = cmds.window("buildWin",t='DS_pvFinder',rtf=1,w=100, h=100, toolbox=True)
column = cmds.columnLayout(adj=True)
def gui(*args):
cmds.columnLayout()
cmds.button(w=300,label='build placement curve',c=printMultiple)
cmds.showWindow(myWindow)
def printMultiple(*args):
root = cmds.ls(sl=True)[0]
child = cmds.listRelatives(root,ad=1,f=True,children=True,type='joint')
child.append(root)
child.reverse()
limbJnt = child
print (child)
armroot = []
for j in limbJnt:
wstJnt = cmds.rename(child[3], 'wrist_BIND')
elbJnt = cmds.rename(child[2], 'elbow_BIND')
sdrJnt = cmds.rename(child[1], 'shoulder_BIND')
clvJnt = cmds.rename(child[0], 'clavicle_BIND')
armroot.append(j)
return armroot
I know I'm in the right ballpark. I just need to know how to properly use the brackets to store the list of what i'm selecting instead of searching all of worldspace and breaking.
Thank you for your help
The code you provided is incomplete, no window is opening, so I tried only the printMultiple function which causes a Error: No object matches name in my case.
Your code cannot work like this since you mix hardcoded names with a loop which does nothing. I suppose your main problem is the order of your renamings. The child array contains absolute names like:
[u'joint1', u'|joint1|joint2', u'|joint1|joint2|joint3']
If you now rename child[0] to 'clavicle_BIND', all the remaining elements in the list become invalid because their real names in the scene now look like this:
[u'clavicle_BIND', u'|clavicle_BIND|joint2', u'|clavicle_BIND|joint2|joint3']
What results in an error at the second rename line. Inverting the order sovles this problem, first rename the leaf node, then the ones above.

Printing in Duplexpage a word document

I am trying to automate the task of printing two copies at double page of ~30 Word document (*.doc). I want to send the program converted to .exe (I plan it just for Windows computers) using py2exe. I know that I can manually check the options but I will not be able to do so on the 20 or so computer where it will be used, as well as I cannot install in this computers new software (That's why I want to convert it into .exe).
I copied this solution to print, but I can't adapt it to do what I want:
from win32com import client
import time
word = client.Dispatch("Word.Application")
filename=input("What files do you want to print?")
def printWordDocument(filename):
"""Given a name of a file prints it. TODO: Add double page."""
word.Documents.Open(filename)
word.ActiveDocument.PrintOut()
time.sleep(2)
word.ActiveDocument.Close()
word.Quit()
I couldn't find any option to print in double pages, or at least automatically, the only option of double page of PrintOut method is ManualDuplexPrint which in the documentation says: "True to print a two-sided document on a printer without a duplex printing kit.", but I don't want to make it even easier to print all the set of documents. And make a program portable to other computers, without modifying the Word documents (I don't create them).
Any other way to do it? Or any other option to do it?
UPDATE
I am not able to code in visual-basic (yet), but if I get a template or some hints I think I will manage to make something adapted to my conditions.
I have ended doing a macro, but this just works for my own computer and not for all the computers where should work.
Sub Test()
'
' Test Macro
' Print in double page and 2 copies
'
ActivePrinter = "Xerox WC 24 PCL"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentWithMarkup, Copies:=2, Pages:="", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub

Categories

Resources