Incremening DataTable values using DP
If you ever came across a situation in which you need to login into the application and do separate steps than you might be interested in this post.
One way to do so is to change action properties and change it to run on all rows, but that will be executing when it completes 1 cycle. what i will be doing here is, dealing with nested actions, a main action will be calling another actions.
For example you have a login action and one more action that selects one of the three options on the basis of login id. So you login the system three times every time with a different id. Create a global sheet paramenter runCount that will stores login count and another parameter currecntCount that will select the option. Its always a good practice to create a main action that calls other actions. So the main action will look like this.
''''''Initialize a variable
''''''Set runCount = 1 in datatable
i = DataTable("runCount",dtGlobalSheet)
''''''Initialize a variable
''''''Set currentCount = 1 in datatable
j =DataTable("currentCount",dtGlobalSheet)
''''''Call to Login action
RunAction "TestLogin", oneIteration
''''''Call Option selection action
RunAction "TestOption", oneIteration
Now on TestLogin action rewrite the code for initialization of i
''''''Initialize i again in TestLogin action
i = DataTable("runCount",dtGlobalSheet)
Now place your checks and start to write your code in login action
If (i = "1") then
''''''TODO steps
''''''Login the site
''''''Check if credential correct else ExitTest
elseif (i = "2") then
''''''TODO steps
''''''Login the site
''''''Check if credential correct else ExitTest
elseif (i = "3") then
''''''TODO steps
''''''Login the site
''''''Check if credential correct else ExitTest
Now do the same initialization of j in TestOption action
j = DataTable("currentCount",dtGlobalSheet)
If (j = "1") then
''''''TODO steps
''''''Select option1 and increment datatable value
DataTable("runCount") = DataTable("runCount") + 1
''''''Call login, where i=2 now
RunAction "TestLogin", oneIteration
''''''After login execution, increment j value
DataTable("currentCount") = DataTable("currentCount") + 1
Elseif ( j = "2") then
''''''TODO steps
''''''Select option2 and increment datatable value
DataTable("runCount") = DataTable("runCount") + 1
''''''Call login, now i=3 here
RunAction "TestLogin", oneIteration
''''''After login execution increment j value
DataTable("currentCount") = DataTable("currentCount") + 1
Elseif ( j = "3") then
''''''TODO steps
''''''Select option3 and increment datatable value
DataTable("runCount") = DataTable("runCount") + 1
So this is how you can work in nested actions and increment dataTable values. Hope it will be useful. :)
One way to do so is to change action properties and change it to run on all rows, but that will be executing when it completes 1 cycle. what i will be doing here is, dealing with nested actions, a main action will be calling another actions.
For example you have a login action and one more action that selects one of the three options on the basis of login id. So you login the system three times every time with a different id. Create a global sheet paramenter runCount that will stores login count and another parameter currecntCount that will select the option. Its always a good practice to create a main action that calls other actions. So the main action will look like this.
''''''Initialize a variable
''''''Set runCount = 1 in datatable
i = DataTable("runCount",dtGlobalSheet)
''''''Initialize a variable
''''''Set currentCount = 1 in datatable
j =DataTable("currentCount",dtGlobalSheet)
''''''Call to Login action
RunAction "TestLogin", oneIteration
''''''Call Option selection action
RunAction "TestOption", oneIteration
Now on TestLogin action rewrite the code for initialization of i
''''''Initialize i again in TestLogin action
i = DataTable("runCount",dtGlobalSheet)
Now place your checks and start to write your code in login action
If (i = "1") then
''''''TODO steps
''''''Login the site
''''''Check if credential correct else ExitTest
elseif (i = "2") then
''''''TODO steps
''''''Login the site
''''''Check if credential correct else ExitTest
elseif (i = "3") then
''''''TODO steps
''''''Login the site
''''''Check if credential correct else ExitTest
Now do the same initialization of j in TestOption action
j = DataTable("currentCount",dtGlobalSheet)
If (j = "1") then
''''''TODO steps
''''''Select option1 and increment datatable value
DataTable("runCount") = DataTable("runCount") + 1
What we have done in the above line is incremented i value, so the datatable value will become 2 this time.
''''''Call login, where i=2 now
RunAction "TestLogin", oneIteration
''''''After login execution, increment j value
DataTable("currentCount") = DataTable("currentCount") + 1
Elseif ( j = "2") then
''''''TODO steps
''''''Select option2 and increment datatable value
DataTable("runCount") = DataTable("runCount") + 1
''''''Call login, now i=3 here
RunAction "TestLogin", oneIteration
''''''After login execution increment j value
DataTable("currentCount") = DataTable("currentCount") + 1
Elseif ( j = "3") then
''''''TODO steps
''''''Select option3 and increment datatable value
DataTable("runCount") = DataTable("runCount") + 1
So this is how you can work in nested actions and increment dataTable values. Hope it will be useful. :)
Comments
Post a Comment