ForEach loop - adapter not available after page changes
Posted: Thu Jun 05, 2014 5:38 pm
Hi There,
I am testing an android app (snapshot attached), there are several pages which display a list of options but follow the same format. Rather than individually mapping all of these elements I thought I would have a go at doing it 'the popper way' and writing a generic solution that would select each of the options in the list and perform some actions - I can then reuse this code whenever I need to test the functionality on other pages with similar lists.
I have a GenericList repo item which identifies each of the items listed on page.
.//container[@rid='viewanimator']/container[@visible='True']//container[@rid='linearLayout1']/text[1]
Here is the code I am using:
The thought has just occurred to me that it is probably the fact that the page changed which means that when the next iteration of the foreach loop resumes the option is not actually pressed.
I have only been using c# as long as Ranorex which is only a couple of months so please excuse my limited understanding of c#
If anyone can tell me where I am going wrong that would be amazing as I plan for this code - or a much more sophisticated enhancement to it to form the basis of most of the testing of this app.
Many thanks
Ben
I am testing an android app (snapshot attached), there are several pages which display a list of options but follow the same format. Rather than individually mapping all of these elements I thought I would have a go at doing it 'the popper way' and writing a generic solution that would select each of the options in the list and perform some actions - I can then reuse this code whenever I need to test the functionality on other pages with similar lists.
I have a GenericList repo item which identifies each of the items listed on page.
.//container[@rid='viewanimator']/container[@visible='True']//container[@rid='linearLayout1']/text[1]
Here is the code I am using:
public void Select_Each_Item() { Report.Info("Select Each Option Listed"); IList<Ranorex.Text> varOptions = repo.ComGroupcallEmerge.ListSearch.GenericListInfo.CreateAdapters<Ranorex.Text>(); Report.Info("User",varOptions.ToString()); if (varOptions.Count >0) { foreach (Ranorex.Text varOption in varOptions) { Report.Info("User","Click on " + varOption.Element.GetAttributeValueText("Text")); varOption.Touch(); Delay.Duration(5000); //Report the new page title then click the back button to return to the list Report.Info("User",repo.ComGroupcallEmerge.LeftPanel.Header.PageTitle.TextValue); Report.Info("User","Clicking on Back Button"); repo.ComGroupcallEmerge.LeftPanel.Header.BackButton.Touch(); Delay.Duration(5000); } } }The list is built and the first option 'Name' is pressed, a new page opens, the title is reported and then then back button is used to return to the page with the original list. The next option in the list should then be pressed but it isn't (even though the report says it has been successfully)
The thought has just occurred to me that it is probably the fact that the page changed which means that when the next iteration of the foreach loop resumes the option is not actually pressed.
I have only been using c# as long as Ranorex which is only a couple of months so please excuse my limited understanding of c#
If anyone can tell me where I am going wrong that would be amazing as I plan for this code - or a much more sophisticated enhancement to it to form the basis of most of the testing of this app.
Many thanks
Ben