How to consume data from a list when running test multiple times?

Good morning guys

I have an automation ready and working to register employees. During registration most of the fields can be filled in with fictitious data and I managed to do it well using FakerLibrary, but there are two fields that I need to inform valid data that I declared like this in the resources file:

*** Variables ***
${CPF} 56932225603 #personal identification document
${ICCID} 89550511260000100099 #simcard code

*** Keywords ***

part of the code where the variables are.

Inform CPF
Wait Until Page Contains Element name=filter
Input Text name=filter ${CPF}
Sleep 5s
Wait Until Page Contains Element xpath=//button[@type=‘submit’][contains(.,‘Search’)]
Click Element xpath=//button[@type=‘submit’][contains(.,‘Search’)]
Sleep 1s
Wait Until Page Contains Element xpath=//h1[contains(.,‘Customer not found!’)]

Inform resources
Wait Until Page Contains Element id=resourcesIccidText
Input Text id=resourcesIccidText ${ICCID}
Set Focus To Element id=btn-wizard-next
sleep 2s
Click Element xpath=//button[@type=‘button’][contains(.,‘NEXT’)]
Wait Until Page Contains Element xpath=//*[text()=‘test@test.com’]

Every time I need to make a new registration, I manually get new data that is in a .txt file and change the variables.
If I need to run the test 10x, I make this change in the variables 10x and here are my doubts:

1 - How do I make the Robot run this test more than once, for example run 4x?
2 - Would it be possible to make these variables be of the list type and each time the test runs it consumes the list?

If the registration succeeds, the ‘CPF and ICCID’ data used cannot be used anymore, so I manually delete them from the .txt file.

1 - Test cases are not repeatable, only Keywords are. So the strategy is to move the test logic to a keyword that can be looped in a FOR or WHILE. Or use an external script to call robot several times.

2 - Yes, you should use lists. You can have then directly defined in Python in an variable file, or a txt file that is read and fill a variable of list type. You can use the BuiiltIn, OperatingSystem, String and Collections libraries for this.
Then you can use the Remove From List keyword after using the values.

Hi Andre,

This is a perfect example of what TestDataTable was designed for.

As Hélio mentioned you create you keyword with ${CPF} and ${ICCID} as arguments.

In TestDataTable, you create an empty table with 2 columns, CPF and ICCID, in these columns import all the unused numbers you have.

Back in your test, make 2 calls to TestDataTable, 1 get a value from the CPF column and 1 to get a value from the ICCID column (when you do this the values are removed from TestDataTable so won’t be given to the next test)

There’s an example here of using TestDataTable with Robot Framework

This last bit’s optional, when you finish up the test you might want to send the CPF and ICCID values back to TestDataTable into some columns called something like Used_CPF and Used_ICCID, you might even want to include the generated name you registered with those values for a future test that validates a CPF or ICCID lookup gets the right employee

Dave.

Hi Hélio,

Thank you for your attention, only junior yet, but I managed to understand your explanation. Doing a very simple test here, I managed to do the FOR and now I just have to see a logic to apply in my test.

André

Hi Dave,

How are you? I hope so… I loved your tip, but the example that passed REST Library, Requests Library, when I try to access it is giving a 404 error.
Reading the TestDataTable documentation I managed to get a little idea.
I’m going to try to install it and populate the table, but I still don’t quite understand how I’m going to call it in the test.
Another very silly doubt I have is about arguments, every time I hear it I get a little lost, because the courses here in Brazil are basic, I can do it well, but when we are going to do something, even if it is not simple, I cannot apply it.
Grateful,
Andre

Hi Andre,

Perhaps this will help

  • You would run TestDataTable on one machine, you might dedicate a machine to the purpose or you might run it run it on a server that’s mainly used for something else (i.e. your defect tracking system), it doesn’t matter which machine you run TestDataTable on as long as your robot machines can access it and it’s always available. Also TestDataTable doesn’t require a lot of resources, so an old retired machine, a Raspberry Pi, anything as long as you can run Python 3.7 on it.
    If you are running TestDataTable on a machine that is shared with something else, you might need to refer to the Configuration section and change the bindport in the configuration file.

  • Once you have TestDataTable running, note the host name / IP address and connect to it using your web browser from you desktop, and set up your table and columns. (for the sake of this post we’ll call the host name is tdtserver and imagine it’s IP address is 192.168.1.13, you can replace these values with your real ones)

  • I gather you downloaded TDT.py and put it in the same folder as your robot file when trying to follow the examples. I should probably make this a bit clearer in the documentation but this example setting will attempt to connect to TestDataTable using http://localhost/ (port 80):

*** Settings ***
Library    TDT.py
  • So you will probably need to tell robot where TestDataTable is (you can copy this from your web browser from the second step):
Library    TDT.py     http://tdtserver

or

Library    TDT.py     http://192.168.1.13

if you changed the port, you’ll need to include that in the url so if you used port 8000, that would look something like:

Library    TDT.py     http://tdtserver:8000

Hopefully that gets you going.

Dave.

Hi Andre,

I just realised I forgot to help you understand about arguments,

  • I guess start here: Using arguments
  • an argument is simply anything you pass to a keyword, if you are familiar with programming a keyword is like a function that can have variables (arguments)
  • also look at the keyword examples here: User keyword arguments

I had a look but couldn’t find any Portuguese translations of the Robot Framework User Guide, maybe @HelioGuilherme66 will know if there is one, his Portuguese is much much better than mine (I don’t really know any Portuguese).

Dave.

Hi Dave,
How are you? I hope well.
The work system is faulty and I couldn’t do an end-to-end test, but after your last message I managed to create the table and columns in the testdatatable.
I managed to make the script consume the CPF and ICCID from the table… and the cool thing that happened what you told me, after consuming the data it was cleared from the table uhuuuuu.
I hope that tomorrow the defect will be corrected, so I’ll do an end-to-end test and see if the logic I set up will make the test run more than once.
As soon as I have news, I’ll post it here.
With all my heart I want to thank you for helping me more this time.
Thank you very much.
Andre

1 Like

About arguments, I couldn’t see this weekend, but as soon as I have some free time here at the service I’ll read the documentation calmly.
As I’m terrible at English, to read the documentation in Portuguese I always translate it in chrome, the examples are horrible but at least I can understand the explanation and once I understand it, I go back to English to see the examples.

1 Like

Hi Andre,

I can imagine how hard it is to read auto translated documentation, I’ve tried with stuff auto translated into English, It’s worst when the source language is Japanese/Korean/Chinese as they are the least like English.

I don’t speak any other language well, I’ve tried leaning a few of my wife’s languages (English was her 4th) but I’m terrible at it. Your written English is very good, I had no trouble understanding you :+1:

Dave.

Hi Dave, how are you?
My script or rather our script (laughs) ran perfectly, my boss loved it. The solution with tdt worked very well, then it was just putting it inside the FOR.
Speaking of FOR, I don’t know if I did it the best way, but it worked, but I still need to understand better, because in this script I had some keywords and when I did the FOR it didn’t go to the next keyword. So I commented them out so that all the action was only on one keyword in FOR.
Robot Framework was my first contact with automation, I’m also studying python, but I have problems sometimes when I need to inspect a screen element.
In the Robot course here, the teacher asked us to install an extension called Truepath in Chrome so that we could get the xpath of the element. But that doesn’t always work, for example, I’m now trying to automate another script that would be for a specific type of employee (compared to the other one, it has seven more fields). It has a field that is a list, I can make the Robot click on it but when the list expands there is nothing I can do to select an item that I want from the list.
Select From List By Index, By Label, By Value nothing works and looking at the code it’s not a list.

About writing in English, I can only do it with the translator. Right now, everything I write to you I pass through the translator from Portuguese to English.

1 Like

Your first success :tada:

Both Python and Robot framework are very much indent controlled, python more so, but the white space is very important for both, this is a good thing because it makes it easier to read and understand what happens where (Reading C code with no indents or line breaks is a real pain, I usually end up reformatting the code to read it)

Consider this example with some dummy keywords:

*** Test Cases ***
My Example Test
    Log Into App
    Do Something Before The Loop
    Navigate To Employees Module
    FOR    ${i}    IN RANGE    3
        Click Create Employee
        Do Something In The Loop
        Do Something Else In The Loop
        Save Employee
        Navigate Back To Employees Module
    END
    Do Something After The Loop
    Log Out Of App

Having the keyword in the loop indented makes it easier to see what happens in the loop and what happens outside the loop.

With the code in your original post it wasn’t clear to me what exactly was happening and without being able to see the app it’s a bit hard to figure out. FYI when you include code in future in the forum use three back ticks (```) on the line before and after your code so your formatting doesn’t get messed up like this"

```
<your code here>
```

Tools like Truepath, are often good as a starting point but the will often give you an xpath lik /div[2]/div[13]/table/tr[5]/td[3]/div[3]/span[2] which might work but if something changes in your app it’ll likely break, so it’s worthwhile learning how to build better xpath yourself. w3schools has one of the best beginner xpath tutorial that I’ve seen and conveniently if you click the globe icon on the right of the menu bar you can select portugese (it’s google translate but at least it’s convenient for you)
image

And once you learn xpath, json path is very similar so you’ll be able to pick that up quickly too.
That site is good for other tutorials as well, so it’s a very handy resource.

Those keywords are for selecting from a <select> / <option> type list, what you have is probably more like a HTML

with rows of data, though with many modern apps the table and rows are often emulated with <div> and <span> tags and CSS.

So to select a specific employee you might need an xpath something like //span[text()="sobrenome do funcionário"]/..//a[text()="editar"]

If the site is publicly available and you can share the link I’ll be able to help you construct xpaths, but if not I’ll still do my best to guide you.

Dave.

1 Like

Hi Dave, how are you? I hope well.
Sorry for not answering you sooner, but yesterday I had to run after some personal matters, because on the 17th I’m going to have surgery on my mouth and I’m going to be away from work for 15 days.
Thanks a lot for the tips.
About xpath, I took a look today at the tutorial you gave me and it looks like it will help me a lot.
The site I’m automating is internal to my service, so I can’t share the url with you, but if you agree, we could exchange information regarding questions by email so I can take a print of what I’m doing and show you. If it’s OK with you, my email is andre.virardi@hotmail.com.
As I will have to rest a lot due to the surgery, as soon as I am able to resume our conversation.
Thanks again for the support and see you soon.
Andre

Hi Andre,

Hope all goes well with your surgery, rest up and look after yourself, work is never more important than your health.

Dave.

Hey Dave, how’s it going? I hope well.
I’m back, the surgery was a success… thanks for the words of comfort.
I need to resume testing with Robot, but now I’m studying Java + Selenium + Cucumber that my company organized.
My boss said either he takes the course and tries to learn Java + Selenium + Cucumber or he’s fired, because here we don’t have anything with Robot or Python.
This comes at a bad time, as my wife and I are buying a house, we also have the factor of my mother-in-law not being able to stay alone and move in with us. And since we have 3 dogs and 11 cats, we have to go to a house that fits them all.
I didn’t want to change because I’ve already made some investments in Robot and Python but unfortunately that’s it here, I’m suffering a lot to find a junior automation vacancy with Robot.

Hi Andre,

Do what you have to for your work, learning Java + Selenium + Cucumber will probably be useful just as you probably learned a lot learning Robot and Python as skills you learn from one will translate roughly to others, the more you learn the more similarities you’ll see between them all.

It will probably also make you realise how much easier Robot is, keep an eye on the job market and when a Robot job pops up apply for it then.

Dave.

1 Like