Problem with contents of enumerator For Each loop (web app)
Posted: Thu Jan 09, 2014 6:30 pm
I have a Ranorex test suite that tests a web-based app using different Windows browsers. There's a separate mobile version of this app, and there is no need for this app to be deployed on other non-Windows operating systems such as Apple/Mac or Linux, so we're only worried about this app working on IE, Firefox, and Chrome at this time.
The overall (simplified) workflow of the Ranorex test suite is as follows:
1. Setup: Open the browser and bring up a fresh form.
2. Start the test case, which is bound to an Excel file containing ~15 data records to enter into the form.
---2a. Enter the information into the form.
---2b. Verify that the form was processed correctly.
---2c. Bring up a fresh form for the next iteration.
3. Teardown: Close the browser.
Within the test case, there is user code that contains a loop that searches for the data record's country within a dropdown list box on the form, using a span tag enumerator:
Dim VarMatchFound as Boolean = False
Do Until VarMatchFound = True
---For Each SpTag as SpanTag In MyRepo.FormName.SelectCountry.Find(".//div[#'cusel-scroll-country']/span")
------Select Case True
---------Case SpTag.InnerText = VarCountry
------------VarMatchFound = True
------------Exit Do
---------Case VarCountry Like "*Col[o,u]mbia" And SpTag.InnerText Like "*Col[o,u]mbia"
------------VarMatchFound = True
------------Exit Do
------End Select
------MyRepo.FormName.SelectCountry.PressKeys("{down}")
---Next SpTag
Loop
The dropdown list box is a custom 3rd-party control. When the form is freshly loaded, the initial text value for the country is United States, because most of the users are based in the U.S. However, if the user clicks on the list box's arrow down, the dropdown list box actually lists the countries in alphabetic order if the user scrolls the list of countries in order.
The loop logic listed above works beautifully in Firefox, Chrome, and even Safari for Windows. It also worked fine in IE 10. However, there's a weird problem when testing this using IE11, as the test proceeds through each iteration of the loop.
The first iteration of the loop always works beautifully.
The second iteration of the loop sometimes does not load the information from the list box into the SpTag enumerator. When that happens, the contents of the SpTag.InnerText ends up being null.
I created a work-around that gets around this problem, but it is ugly and slows things down:
Dim VarMatchFound as Boolean = False
Do Until VarMatchFound = True
---For Each SpTag as SpanTag In MyRepo.FormName.SelectCountry.Find(".//div[#'cusel-scroll-country']/span")
------Select Case True
---------Case SpTag.InnerText = VarCountry
------------VarMatchFound = True
------------Exit Do
---------Case VarCountry Like "*Col[o,u]mbia" And SpTag.InnerText Like "*Col[o,u]mbia"
------------VarMatchFound = True
------------Exit Do
---------Case MyRepo.FormName.SelectCountry.InnerText = VarCountry
------------VarMatchFound = True
------------Exit Do
---------Case VarCountry Like "*Col[o,u]mbia" And MyRepo.FormName.SelectCountry.InnerText Like "*Col[o,u]mbia"
------------VarMatchFound = True
------------Exit Do
------End Select
------MyRepo.FormName.SelectCountry.PressKeys("{down}")
---Next SpTag
Loop
I've run this workaround in debug mode to see if I could find some kind of pattern as to which iterations would work correctly and which iterations used the workaround cases. After running repeated tests, I have not observed any particular patterns. It is impossible to predict which iterations will load the enumerator, and which ones will not.
Can anyone help me figure out why the original code is unable to load the enumerator properly for each iteration in IE 11?
Thanks in advance,
SZ
The overall (simplified) workflow of the Ranorex test suite is as follows:
1. Setup: Open the browser and bring up a fresh form.
2. Start the test case, which is bound to an Excel file containing ~15 data records to enter into the form.
---2a. Enter the information into the form.
---2b. Verify that the form was processed correctly.
---2c. Bring up a fresh form for the next iteration.
3. Teardown: Close the browser.
Within the test case, there is user code that contains a loop that searches for the data record's country within a dropdown list box on the form, using a span tag enumerator:
Dim VarMatchFound as Boolean = False
Do Until VarMatchFound = True
---For Each SpTag as SpanTag In MyRepo.FormName.SelectCountry.Find(".//div[#'cusel-scroll-country']/span")
------Select Case True
---------Case SpTag.InnerText = VarCountry
------------VarMatchFound = True
------------Exit Do
---------Case VarCountry Like "*Col[o,u]mbia" And SpTag.InnerText Like "*Col[o,u]mbia"
------------VarMatchFound = True
------------Exit Do
------End Select
------MyRepo.FormName.SelectCountry.PressKeys("{down}")
---Next SpTag
Loop
The dropdown list box is a custom 3rd-party control. When the form is freshly loaded, the initial text value for the country is United States, because most of the users are based in the U.S. However, if the user clicks on the list box's arrow down, the dropdown list box actually lists the countries in alphabetic order if the user scrolls the list of countries in order.
The loop logic listed above works beautifully in Firefox, Chrome, and even Safari for Windows. It also worked fine in IE 10. However, there's a weird problem when testing this using IE11, as the test proceeds through each iteration of the loop.
The first iteration of the loop always works beautifully.
The second iteration of the loop sometimes does not load the information from the list box into the SpTag enumerator. When that happens, the contents of the SpTag.InnerText ends up being null.
I created a work-around that gets around this problem, but it is ugly and slows things down:
Dim VarMatchFound as Boolean = False
Do Until VarMatchFound = True
---For Each SpTag as SpanTag In MyRepo.FormName.SelectCountry.Find(".//div[#'cusel-scroll-country']/span")
------Select Case True
---------Case SpTag.InnerText = VarCountry
------------VarMatchFound = True
------------Exit Do
---------Case VarCountry Like "*Col[o,u]mbia" And SpTag.InnerText Like "*Col[o,u]mbia"
------------VarMatchFound = True
------------Exit Do
---------Case MyRepo.FormName.SelectCountry.InnerText = VarCountry
------------VarMatchFound = True
------------Exit Do
---------Case VarCountry Like "*Col[o,u]mbia" And MyRepo.FormName.SelectCountry.InnerText Like "*Col[o,u]mbia"
------------VarMatchFound = True
------------Exit Do
------End Select
------MyRepo.FormName.SelectCountry.PressKeys("{down}")
---Next SpTag
Loop
I've run this workaround in debug mode to see if I could find some kind of pattern as to which iterations would work correctly and which iterations used the workaround cases. After running repeated tests, I have not observed any particular patterns. It is impossible to predict which iterations will load the enumerator, and which ones will not.
Can anyone help me figure out why the original code is unable to load the enumerator properly for each iteration in IE 11?
Thanks in advance,
SZ