Hi,
I extract values from more elements and I want then to choose randomly one of them:
1. Extract selection 'ByValue' on 'Normalpreis' into DataBindVariable $(normal_pk)
2. Extract selection 'ByValue' on 'ermasigt' into DataBindVariable $(ermasigt_pk)
2. [Choose_random_price_cat_CodedStep] : Select 'ByValue' option '1' on 'Cat274411276264077Select':
Dim n_pc As Object = GetExtractedValue("normal_pk")
Dim e_pc As Object = GetExtractedValue("ermasigt_pk")
Dim norm_pc As String = CType(n_pc, String)
Dim erma_pc As String = CType(e_pc, String)
Dim random As New System.Random()
Dim i As Integer = random.[Next](1, 2)
Dim j As Integer = random.[Next](1, 5)
Dim avail_pk() As String = {norm_pc, erma_pc}
'Select 'ByValue' option '1' on 'Cat274411276264077Select'
Pages.FindEventsWebSales2.avail_pk(i).SelectByValue(j, true) ' originaly instead of avail_pk(i) it was Cat274411276264077Select
'Invoke jQuery 'select' event'
Dim jQueryControl As ArtOfTest.WebAii.jQuery.jQueryControl = Pages.FindEventsWebSales2.avail_pk(i).AsjQueryControl
jQueryControl.InvokejQueryEvent(ArtOfTest.WebAii.jQuery.jQueryControl.jQueryControlEvents.change)
Can anybody help me?
BR, Jurij
14 Answers, 1 is accepted
I forgot to mention before that I get the folowing error when running above test:
C:\Users\User\Documents\Test Studio Projects\WebSales\Randomly choose price cat and nr of tix\Choose random price cat.tstest.vb: Line 68: (BC30456) 'avail_pk' is not a member of 'Pages.FindEventsWebSales2Page'.C:\Users\User\Documents\Test Studio Projects\WebSales\Randomly choose price cat and nr of tix\Choose random price cat.tstest.vb: Line 71: (BC30456) 'avail_pk' is not a member of 'Pages.FindEventsWebSales2Page'.
BR, Jurij
I found out that I was extrtacting the wrong value, so I have changed that, but still I get an error when running test case:
1. Extract 'id' attribute on 'Cat274411276264076Select0' into DataBindVariable $(pk1-0) <- AttributeValue: cat-2744112-76264076
2. CodedStep1: Select 'ByValue' option 'randomNr' on 'SelectedPriceCat':
'Select 'ByValue' option 'randomNr' on 'SelectedPriceCat'
Dim a_pc As Object = GetExtractedValue("pk1-0")
Dim b_pc As Object = GetExtractedValue("pk1-1")
Dim norm_pc As String = CType(a_pc, String)
Dim erma_pc As String = CType(b_pc, String)
Dim n_pc As String = norm_pc.Replace("-", "")
Dim e_pc As String = erma_pc.Replace("-", "")
Dim no_pc As String = n_pc.Replace("cat", "Cat")
Dim er_pc As String = e_pc.Replace("cat", "Cat")
Dim lstPrices As List(Of String)
lstPrices.Add(no_pc)
lstPrices.Add(er_pc)
Dim random As New System.Random()
Dim i As Integer = random.[Next](2)
Dim rndPrice As String = lstPrices(i)
Dim rndPriceSelected As String = rndPrice & "Select"
'Select 'ByValue' option '1' on 'Cat274411276264077Select'
Pages.FindEventsWebSales2.rndPriceSelected.SelectByValue(i, true)
'Invoke jQuery 'select' event'
Dim jQueryControl As ArtOfTest.WebAii.jQuery.jQueryControl = Pages.FindEventsWebSales2.rndPriceSelected.AsjQueryControl
jQueryControl.InvokejQueryEvent(ArtOfTest.WebAii.jQuery.jQueryControl.jQueryControlEvents.change)
Error that I get:
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Client\Add to cart.tstest.vb: Line 86: (BC30456) 'rnd_pc' is not a member of 'Pages.FindEventsWebSales2Page'.C:\Users\jurij\Documents\Test Studio Projects\WebSales\Client\Add to cart.tstest.vb: Line 89: (BC30456) 'rnd_pc' is not a member of 'Pages.FindEventsWebSales2Page'.
Can somebody help me out?
Thanks, Jurij
Do you have defined somewhere rnd_pc? If not the exception is expected.
Open this test C:\Users\jurij\Documents\Test Studio Projects\WebSales\Client\Add to cart.tstest and double check where do you use it and how it defined.
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik
rnd_pc was used before and changed to rndPrice, see code below:
'Select 'ByValue' option 'randomNr' on 'SelectedPriceCat'
Dim a_pc As Object = GetExtractedValue("pk1-0")
Dim b_pc As Object = GetExtractedValue("pk1-1")
Dim c_pc As Object = GetExtractedValue("pk1-2")
Dim d_pc As Object = GetExtractedValue("pk1-3")
Dim norm_pc As String = CType(a_pc, String)
Dim erma_pc As String = CType(b_pc, String)
Dim kind_pc As String = CType(c_pc, String)
Dim prom_pc As String = CType(d_pc, String)
Dim n_pc As String = norm_pc.Replace("-", "")
Dim e_pc As String = erma_pc.Replace("-", "")
Dim k_pc As String = kind_pc.Replace("-", "")
Dim p_pc As String = prom_pc.Replace("-", "")
Dim no_pc As String = n_pc.Replace("cat", "Cat")
Dim er_pc As String = e_pc.Replace("cat", "Cat")
Dim ki_pc As String = k_pc.Replace("cat", "Cat")
Dim pr_pc As String = p_pc.Replace("cat", "Cat")
Dim lstPrices As List(Of String)
lstPrices.Add(no_pc)
lstPrices.Add(er_pc)
lstPrices.Add(ki_pc)
lstPrices.Add(pr_pc)
Dim random As New System.Random()
Dim i As Integer = random.[Next](4)
Dim rndPrice As String = lstPrices(i)
Dim rndPriceSelected As String = rndPrice & "Select"
'Select 'ByValue' option '1' on 'Cat274411276264077Select'
Pages.FindEventsWebSales2.rndPriceSelected.SelectByValue(i, true)
'Invoke jQuery 'select' event'
Dim jQueryControl As ArtOfTest.WebAii.jQuery.jQueryControl = Pages.FindEventsWebSales2.rndPriceSelected.AsjQueryControl
jQueryControl.InvokejQueryEvent(ArtOfTest.WebAii.jQuery.jQueryControl.jQueryControlEvents.change)
Still I get error:
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Client\Add to cart.tstest.vb: Line 89: (BC30456) 'rndPriceSelected' is not a member of 'Pages.FindEventsWebSales2Page'.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Client\Add to cart.tstest.vb: Line 92: (BC30456) 'rndPriceSelected' is not a member of 'Pages.FindEventsWebSales2Page'.
BR, Jurij
rnd_pc was changed to rndPrice, but I still get an error. See code used:
'Select 'ByValue' option 'randomNr' on 'SelectedPriceCat'
Dim a_pc As Object = GetExtractedValue("pk1-0")
Dim b_pc As Object = GetExtractedValue("pk1-1")
Dim c_pc As Object = GetExtractedValue("pk1-2")
Dim d_pc As Object = GetExtractedValue("pk1-3")
Dim norm_pc As String = CType(a_pc, String)
Dim erma_pc As String = CType(b_pc, String)
Dim kind_pc As String = CType(c_pc, String)
Dim prom_pc As String = CType(d_pc, String)
Dim n_pc As String = norm_pc.Replace("-", "")
Dim e_pc As String = erma_pc.Replace("-", "")
Dim k_pc As String = kind_pc.Replace("-", "")
Dim p_pc As String = prom_pc.Replace("-", "")
Dim no_pc As String = n_pc.Replace("cat", "Cat")
Dim er_pc As String = e_pc.Replace("cat", "Cat")
Dim ki_pc As String = k_pc.Replace("cat", "Cat")
Dim pr_pc As String = p_pc.Replace("cat", "Cat")
Dim lstPrices As List(Of String)
lstPrices.Add(no_pc)
lstPrices.Add(er_pc)
lstPrices.Add(ki_pc)
lstPrices.Add(pr_pc)
Dim random As New System.Random()
Dim i As Integer = random.[Next](4)
Dim rndPrice As String = lstPrices(i)
Dim rndPriceSelected As String = rndPrice & "Select"
'Select 'ByValue' option '1' on 'Cat274411276264077Select'
Pages.FindEventsWebSales2.rndPriceSelected.SelectByValue(i, true)
'Invoke jQuery 'select' event'
Dim jQueryControl As ArtOfTest.WebAii.jQuery.jQueryControl = Pages.FindEventsWebSales2.rndPriceSelected.AsjQueryControl
jQueryControl.InvokejQueryEvent(ArtOfTest.WebAii.jQuery.jQueryControl.jQueryControlEvents.change)
Error:
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Client\Add to cart.tstest.vb: Line 89: (BC30456) 'rndPriceSelected' is not a member of 'Pages.FindEventsWebSales2Page'.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Client\Add to cart.tstest.vb: Line 92: (BC30456) 'rndPriceSelected' is not a member of 'Pages.FindEventsWebSales2Page'.
BR, Jurij
The error seems to be different now: 'rndPriceSelected' is not a member of 'Pages.FindEventsWebSales2Page'.
Are you able to find rndPriceSelected under FindEventsWebSales2Page node? You should find under which node is this element and fix your code.
If the issue persists please send us your project so we can review it.
Thank you.
Regards,
Boyan Boev
Telerik
Yes, its different error, but I don't understand your reply as rndPriceSelected is string variable which I have created:
Dim rndPriceSelected As String = rndPrice & "Select"
How can I find rndPriceSelected under FindEventsWebSales2Page node?
I'm a novice in this, so please bear with me as I try to understand how test studio works.
BR, Jurij
OK, let's go back to the start. My goal is to have a test case which randomly chooses price category. On the page we have:
priceCat1,
priceCat2 and so on
All are dropdown menus with values ranging from 1 to 250.
Now I want to randomly choose priceCat and select any value.
How can I achieve something like this?
Thanks and BR, Jurij
Elements are always stored under a page that the element appeared on so that we don't accidentally reference the same element such as a button e.t.c., on two different pages.
Sometimes the URL of the page has some dynamic content, such as a dynamic query string and it will result in multiple pages being needlessly created.
Be default Test Studio considers each unique URL, including the query string, to be a different page.
In some applications it's better to adjust the settings so that Test Studio will ignore the query string.
Regarding the question you should generate a random number in a coded step and then use it as a variable in the select step in Test Studio.
It will be really helpful if you can send me the project and access to the application so I can help with the code.
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik
Hi Boyan,
Unfortunately we would expose to much to the outside if we grant you access to our application. Instead I have attached snippet of the code where I would like randomly choose an element and its value.
Goal is as said to randomly choose between available price categories: "cat[2744112][76264076]", "cat[2744112][76264077]" and "cat[2744112][76264078]". After choosing price category then I would like to randomly choose a value for the chosen price category.
Code to chose random value I already have:
'Select 'ByValue' option 'randomNr' on 'SelectedPriceCat'
Dim random As New System.Random()
Dim i As Integer = random.[Next](1, 6)
Pages.FindEventsWebSales2.Cat274411276264076Select.SelectByValue(i, True)
'Invoke jQuery 'select' event'
Dim jQueryControl As ArtOfTest.WebAii.jQuery.jQueryControl = Pages.FindEventsWebSales2.Cat274411276264076Select.AsjQueryControl
jQueryControl.InvokejQueryEvent(ArtOfTest.WebAii.jQuery.jQueryControl.jQueryControlEvents.change)
Can you still help or is this dead end for us?
Thanks and best regards, Jurij
I've found this (changed to our html elements):
HtmlTable myTable = ActiveBrowser.Find.ByAttributes<HtmlTable>("class=?col4 sel");
IList<HtmlTableRow> myList = myTable.Find.AllByTagName<HtmlTableRow>("name");
foreach (HtmlTableRow rows in myList)
{
Log.WriteLine(rows.InnerText.ToString());
}
The problem is that I've made a coded step, pasted above in this step and ran the test. Test failed with following errors:
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 131: (BC30108) 'HtmlTable' is a type and cannot be used as an expression.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 131: (BC30800) Method arguments must be enclosed in parentheses.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 131: (BC30451) 'myTable' is not declared. It may be inaccessible due to its protection level.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 131: (BC30108) 'HtmlTable' is a type and cannot be used as an expression.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 131: (BC30037) Character is not valid.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 132: (BC32042) Too few type arguments to 'System.Collections.Generic.IList(Of T)'.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 132: (BC30800) Method arguments must be enclosed in parentheses.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 132: (BC31198) XML literal cannot appear here unless it is enclosed in parentheses.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 132: (BC30108) 'HtmlTableRow' is a type and cannot be used as an expression.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 132: (BC30451) 'myList' is not declared. It may be inaccessible due to its protection level.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 132: (BC30451) 'myTable' is not declared. It may be inaccessible due to its protection level.
C:\Users\jurij\Documents\Test Studio Projects\WebSales\Zephyr\Best seat booking\WSA 446 Best seat booking - Euroticket event.tstest.vb: Line 132: (BC30108) 'HtmlTableRow' is a type and cannot be used as an expression.
What I'm doing wrong?
BR, Jurij
From the first sight as far as I can see you are using C# code in VB project.
Also as Boyan stated before without having access to the application we cannot assist with writing the code for you.
Thank you for your understanding.
Regards,
Ivaylo
Telerik
OK, I understand, but before I consult on this within our company I would like to see an example how the C# code can be written in VB:
HtmlTable myTable = ActiveBrowser.Find.ByAttributes<HtmlTable>("class=?col4 sel");
IList<HtmlTableRow> myList = myTable.Find.AllByTagName<HtmlTableRow>("name");
foreach (HtmlTableRow rows in myList)
{
Log.WriteLine(rows.InnerText.ToString());
}
BR, Jurij