HomeOATS

Openscript test data parameterization with databanks

Openscript test data parameterization with databanks
Like Tweet Pin it Share Share Email

As you all know the main purpose of creating automation test scripts is to run the scripts for multiple sets of data and increase the test coverage with several combinations of test data, while there are several ways to parameterize scripts in Oracle Application testing suite, let us look at Openscript test data parameterization with databanks in this article, which is by using CSV Files.

Assuming that you know how to record a script using openscript, once you have recorded a specific test case in openscript, the first thing you need to identify is what are all the input data that you want to parametrize so that the same script can be executed repeatedly for different sets of test data.

Just to keep the understanding easy & clear, let me explain you with an example here:

You can navigate to signup page of developer.salesforce website you would see a registration page as below:

salesforce-sign-up-page

There are 9 input fields in the above registration page, but as per this test case let us consider that, you want to run this test case for registering only developers from India residing in a specific Postal Code. So when you consider this scenario, there is no use of parametrizing test data for fields like “Role“,”Country“,”Postal Code” and checking the checkbox to accept agreement as they remain constant as per the above consideration.

Now we are left with the following fields, which could be parametrized for executing the scripts for multiple sets of test data.

  • First Name
  • Last Name
  • Email
  • Company
  • Username

Let us first see how the script looks when creating  a script to register in the above website:

Script Before Parameterization

Now, in order to parametrize the fields as per above, perform the below steps:

Steps to add a CSV File based databank @ openscript for test data parametrization

  • Click on “Assets” tab of the script’
  • Select Databanks in the tree
  • Click on Add button on the right side of the window
  • Select “CSV File” option

Add_CSV_Databank_Openscript_Parametrization

  • Navigate to desired folder location as where you want to store the databank.
  • Give a name for example “register-test-data” and click on OK Button.

register-test-data

  • Select the newly created databank in “Assets” tab and click on “Open” Button
  • You will be presented with a plain text editor in the openscript IDE.
  • Now, enter the field names you want to parametrize with comma separated names i.e. firstname,lastname,email,company,username
  • Note: the first row in this file is considered as parametrized names for these fields.
  • Now you need to give multiple sets of data that you want to use for registering the website as below:

testdata-parametrize-databank-openscript

Now that you have successfully created a databank for this script, lets follow the below steps to parametrize the script with this databank.

Steps to parametrize script using the CSV File based Databank

  • Navigate to “TreeView” of the script.
  • Double click on “first_name” field in the treeview

firstname_select_for_parameterization_double_click

  • You will be presented with a window by name “Set Text” which contains the first name that you have given during the time the script was recorded.

settext_parameterizatin

  • Now click on parametrize-cion  icon to parametrize the data
  • You will be presented with a window “Substitute Variable”

substitute_variable

  • In that window you can see a databank with name “register-test-data” that you have created some time back.
  • Select “firstname” and click finish.

select_firstname

  • You can now see that an expression is inserted in the place where data was present earlier.

firstname_parameterized

  • Click OK button.

There it is you are done with parametrization of firstname field, repeat the same steps to parametrize other fields and you would be done with test data parametrization as below:

script_parameterized_databank_csv

You are all set now with test data parametrization for the desired fields, in the above example we have given 2 sets of test data in the CSV file based databank, in order to execute this script for all test data sets, you need to click on iterate (iterate) button in the openscript IDE and not the normal playback button and click on “OK” button when you are presented with “Iterate” window. The default settings in this window is the execute for all sets of test data provided in databank.

In case of any queries, please feel free to reach out to me through comments, I would be more than happy to assist you in this.

 

lambdatest

Comments (30)

  • That is an amazing work!
    Thank you so much for your time
    I have a question that how we can restrict iteration on the specific group? Because on each iteration, it is being started from the 1st group of the tree.

    Reply
    • Author

      Hi Faisal,

      Thank you so much for reaching out to us on iterations in Oracle Applications Testing Suite, could you please elaborate your query, as what do you mean by specific group???

      If you were referring to step group, there is no direct way of doing it, but you could write your own logic to understand which iteration the script is currently executing and then you can write some conditional logic to only execute those groups which you want to get executed, hope this clarifies your query.

      Please do let me know if you have any further queries, I would be more than happy to help you.

      Thanks,
      Srinivas P.

      Reply
  • Hello,
    I follow what you said. Its Amazing. But i have a query that if i have up to 20 Records in Single Data bank of a Script and i started running Script. If my 2nd record of that data bank has wrong values and it got failed. So i want a logic by which if 2nd Record have failed it have to continuous to run 3rd record up to 20th records
    Is that possible

    Reply
  • This is more clear. Thank you
    i have a quick question.Is there any method/per-defined option to set value back to .csv file using databank?

    Reply
    • Author

      Unfortunately there is no pre-defined methods available for this purpose, but you can try POI Library for this specific need.

      Reply
  • Hi Srinivas,

    I am working on Openscript. I want to know how to get the value of a particular input parameter while using .csv file as an input data sheet.
    I tried using below code to get the value of username but it returns as null
    getDatabank(
    “testing”)
    .getNextDatabankRecord();
    String username = getVariables().get(“Username”);
    info(“Username: “+username);
    Output:
    Username: null
    even though i have provided the value in input data file(.csv)

    Reply
    • Author

      Hi Sushma,

      First thing, in order to access data from databank, we cannot use getVariables().get(“Username”); there is another API if you want to retreive data from databank.
      It should be something like below:

      String username = “{{db.dbaliasname.colname}}”;

      Also, is it possible to share
      1. CSV file contents
      2. The way you associated the csv file as a databank.

      In case you followed the steps carefully in this article, once you are done with all the steps, click on “Code View” and you can actually see the equivalent code, for connecting to databank, retrieving data from databank.

      I hope this will give you a direction.

      Thank you,
      regards,
      Srinivas P.

      Reply
  • Hi,

    Can you please tell me, how to get value from databank and store it in a variable?

    Reply
  • In openscript my oracle application open the HTML but when open the Java forms..it’s not recorded in openscript.
    Java jre 1.8.0_161
    Openscript ver: 13.2.0.1 build 203
    Thanks,

    Reply
  • Forgot to mention Java forms open but my actions on Java forms are not recorded in openscript. The last script I move my mouse …it’s says ..”cannot remove the node”

    Thanks,

    Reply
    • Author

      I am guessing it might be because in OATS the JRE version is not selected or the JRE and OATS version are not compatible.

      Reply
  • Hello,

    I am new to this oracle oats,Suppose i am storeing some values in a variable and then want to write it back to csv file.can i do this?

    Thanks and Regards
    Subhasish

    Reply
    • Author

      Yes you can do it, you may have to write some reusable functions to interact with csv file ( with help of POI library )

      Reply
  • Hello,

    Do you know how to open a databank as read only?, I have multiple scripts using the same databank but I cannot run a simultaneous execution because openscript open the databank as write/read.

    Thanks!

    Reply
    • Author

      Hi Raul,

      It may not be possible with databank, but I was thinking you can use POI library and open excel or csv files in read only mode and it might not create a problem i guess. But you have to write your own libraries if you want to reuse them across projects.

      Reply
  • Hi Srinivas

    What are these POI libriaries?
    How to use them? any example codes?

    My aim is to capture some fields from application and print it to the csv file.

    Thanks
    Harsha

    Reply
    • Author

      Sure Harsha,

      I would write an article soon to interact with Excel Files using POI libraries. Until then you may have to wait 🙂

      Thank You,
      Regards,
      Srinivas P.

      Reply
  • Hi ,
    Is it possible to store output data into databank through script??

    Reply
    • Author

      I think there is some api given by oats to save to csv files, i think you should try to use that

      Reply
  • Hell Srinivas,

    I am very new to OFT. I have finally started and run some scripts via ‘iterative’. I having managed to pass multiple users through a single scripts. What I am struggling with is how to set-up adding multiple scripts to a single bank and running multiple users through that. Is this possible?

    Reply
    • Author

      sorry for the delay in response, it is ideally not a good practice to add multiple scripts to same databank, you may need to create another Master Script which will point to another DataBank where you have the list of test scripts and when you iterate through them you will basically execute each script to iterate with the appropriate api, please do let me know if you are still looking for this.

      Reply
  • Hi Srinivas,

    I am new to OATS. I want to upload a file from upload window wizard, I am trying to read file path from databank and should pass it to StringSelection class to paste the path to file upload window using Robot class.

    In file upload window it is not pasting the “file path” instead it is printing “{{db.dbname.filepath}”.

    Could you please let me know how to proceed with this.

    Code :
    String file = {{db.dbname.filepath}}”;
    info(“File path is :”+file);

    StringSelection strsel = new StringSelection(path);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strsel, null);

    Reply
    • Author

      Yes that is what is expected, but if you want this to work in the way you are expecting, you will need to use an additional API of OATS to resolve the format and give you the actual string.
      Before that i would like to explain you something, any format which is like “{{db.dbname.filepath}}” these are notations supported by OATS and they get automatically resolved when used with OATS api.

      for example in the following code

      String filePath = “{{db.dbname.filepath}}”;
      info(filePath);

      info is also an API provided by OATS, so in this case you will see that the value is properly printed, because the OATS APIs resolves all the formats by default

      but if we use the same in regular java code you will get the same what is present in filePath variable

      String filePath = “{{db.dbname.filepath}}”;
      System.out.println(filePath);

      With this code the value will be printed same to what is assigned to the String variable.

      But in order to address this, there is an API called eval , so if you change the above code to following format then in even in regular java code, you will get the resolved value.

      // eval function resolves the format and returns the desired value
      String filePath = eval(“{{db.dbname.filepath}}”);
      System.out.println(filePath);

      Now you will get the value which you wanted to see.

      Hope this helps.

      Reply
  • corrected code:

    Code :
    String file = “{{db.dbname.filepath}}”;
    info(“File path is :”+file);

    StringSelection strsel = new StringSelection(file);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strsel, null);

    Reply
  • @Srinivas How to disable element highlight on execution in openscript? Currently on execution element get’s highlighted with red box.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *