This is a migrated thread and some comments may be shown as answers.

asp gridview with test studio

14 Answers 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 25 Jun 2013, 02:39 PM

Hi,

I have an asp gridview that display users, I want a test to add a user then for example edit the user by changing the password. The problem I have is that the gridview contains upwards of 80 users and the pagesize is set to 15. Is there a way to get test studio to loop/iterate through each row (including changing to page 2, 3 etc) until it finds the username I have specified?

Any help on this would b great because I have quite a few gridviews I need to test which I foresee having similar problems

Thanks

Jo

 

14 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 26 Jun 2013, 11:32 AM
Hello Joseph,

You can handle this functionality by a single coded step. I created a sample against our demo site.

int page = 2;    //this is the number of the page.
bool notFound = true; //Indicates whether the element is found or not.
             
 
            IList<HtmlTableCell> myList = ActiveBrowser.Find.AllByTagName<HtmlTableCell>("td");
            while (notFound)
            {
                foreach (HtmlTableCell item in myList)
                {
                    
                    if (item.InnerText.Contains("Peugeot"))
                    {
                        //Click, edit, verify
                        Log.WriteLine("I have found it");
                        notFound = false;
                    }
                     
 
 
                }
 
 
                //Find the link for the next page and click on it.
                HtmlTable myTable = ActiveBrowser.Find.ById<HtmlTable>("ctl00_ContentPlaceHolder1_RadGrid1_ctl00");
                myTable.Find.ByContent<HtmlSpan>(page.ToString()).Click();
 
                page++;
            }

Here is a video demonstration.

Hope this helps.

Regards,
Boyan Boev
Telerik
Free summer webinars on advanced web automation tactics hosted by Jim Holmes & Adam Goucher.
Reserve your seat today!
0
Joseph
Top achievements
Rank 1
answered on 27 Jun 2013, 10:17 AM
Hi Boyan,

Thanks for the reply, that is exactly what im looking for, but i cant seem to get it to work. i have entered the code and and changed it to suit my project but i keep getting the error:

Exception thrown executing coded step: '[Notes_CodedStep] : New Coded Step'.
InnerException:
ArtOfTest.WebAii.Exceptions.FindException: Find Details:
- FindParam used: [Find logic: Use 'AttributesOnly' for tag 'td' where (none) ]
- Start Element: null

I am using a asp:gridview and i notice that the exmaple video shows a radGrid, would this cause any problems?

Thanks

Jo
0
Joseph
Top achievements
Rank 1
answered on 28 Jun 2013, 12:45 PM
Hi,
*Update*

i have been looking into ur code some more and i seem to have found an error with it. I tried using my own project to no avail so i decided to use ur test website with the exact code u supplied. If i search for a car name (Mitsubishi) which appears on the 3rd page the test never actually changes page and still it suggests the test was a success. This doesnt seem to be the case though, if i read through the log it only finds the car name (Mitsubishi) in the "select a brand" drop down list, I then tried again by searching for other text that wasnt in a drop down list (320d for example) the test fails and cannot find anything.

With regards to the tests im trying to carry out, i need it to check everypage not just the first.

Any help would be great

Thanks

Jo
0
Joseph
Top achievements
Rank 1
answered on 01 Jul 2013, 08:51 AM
Hi,
*Update*

i have been looking into your code some more and i seem to have found an error with it. I tried using my own project to no avail so i decided to use ur test website with the exact code you supplied. If i search for a car name (Mitsubishi) which appears on the 3rd page the test never actually changes page and still it suggests the test was a success. This doesnt seem to be the case though, if i read through the log it only finds the car name (Mitsubishi) in the "select a brand" drop down list, I then tried again by searching for other text that wasnt in a drop down list (320d for example) the test fails and cannot find anything.

With regards to the tests im trying to carry out, i need it to check everypage not just the first.

Any help would be great

Thanks

Jo
0
Boyan Boev
Telerik team
answered on 01 Jul 2013, 10:08 AM
Hello Joseph,

As you can see in the video, it is changing the pages. It is not looking on the first page only.

Is there any way you can provide us with access to the application you are testing so I can write the code for you.

If you are not able to provide direct access another option is to create a fiddler trace using FiddlerCap and send it over.

Hope to hear from you soon.

Regards,
Boyan Boev
Telerik
Free summer webinars on advanced web automation tactics hosted by Jim Holmes & Adam Goucher.
Reserve your seat today!
0
Joseph
Top achievements
Rank 1
answered on 01 Jul 2013, 10:50 AM
Hi Boyan,

Sorry I should have been more clear, I realise the video is changing pages, but it doesn't perform correctly on my project, I have used the code you supplied and the website you have used, I'm afraid I will not be able to give you access to our projects as they contain confidential information etc. I have created a fiddler as requested and attached it, never used this program before so not 100% if its correct (I opened fiddler , pressed capture, ran the test then stopped)

The only part of the code that seems to make a difference is the starting page int, if I set this to 1 the pages never change, but if I change this to 2, 3 or 4 the table skips straight to that page, as I need to search the whole grid view I will be unable to specify a specific page. below is my code, it suggests a successful test but the pages never change, which leads me to assume either the car name is being found in the drop down list or the 'page++' is not working correctly

Thanks

Jo
------

Site used : http://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx
int page = 1;    //this is the number of the page.
bool notFound = true; //Indicates whether the element is found or not.
 
            IList<HtmlTableCell> myList = ActiveBrowser.Find.AllByTagName<HtmlTableCell>("td");
 
            while (notFound)
            {
                foreach (HtmlTableCell item in myList)
                {
                    if (item.InnerText.Contains("Mitsubishi"))
                    {
                        //Click, edit, verify
                        Log.WriteLine("I have found it");
                        notFound = false;
                    }
                }
 
                //Find the link for the next page and click on it.
                HtmlTable myTable = ActiveBrowser.Find.ById<HtmlTable>("ctl00_ContentPlaceHolder1_RadGrid1_ctl00");
                myTable.Find.ByContent<HtmlSpan>(page.ToString()).Click();
 
                page++;
            }

0
Boyan Boev
Telerik team
answered on 02 Jul 2013, 11:39 AM
Hello Joseph,

I am a little confused. You have captured a Fiddler trace of our demo site. The code I've provided works without any problems against this site.

Please record a Fiddler trace against your site so I can write a code for your application.

Another option is to give us an access to a sample application without the data. We don't need the data. We need just the structure of the application.

Could your developers create some sample application with the same structure and make it publicly accessible?

Hope to hear from you soon.

Regards,
Boyan Boev
Telerik
Free summer webinars on advanced web automation tactics hosted by Jim Holmes & Adam Goucher.
Reserve your seat today!
0
Joseph
Top achievements
Rank 1
answered on 02 Jul 2013, 04:25 PM
Hi Boyan,

Sorry I thought I mentioned that fiddler was for your test site, it was more to show you what I was doing and how it wouldn't work on my end, with the starting page (1) when searching for a value that appears on page 3 etc.

I have attached a fiddler of our project, I'm not sure how much details it shows but, the gridview in questions contains two values, 'Clinical' and 'Non-Clinical' (roughly 18 of each with a pageSize of 15 so in total 3 pages) , in this demo test I am looking for Clinical which would appear on page 2,3. but as the fiddler will hopefully show; the gridview pages never change.

Thanks

Jo

*Sorry that probably wasn't a very good demo/example gridview, I realise the code probably couldn't differentiate between the two types of clinical, I have attached another fiddler (Updated Fiddler.zip) which uses the same gridview but looks for ID instead which is different for each row, in the fiddler im searching for 1444441 which appears on the second page
0
Velin Koychev
Telerik team
answered on 05 Jul 2013, 11:38 AM
Hi Joseph,

Thank you for providing us with the new Fiddler traces. 

I've made some small changes on the code and it should work now:

int page = 1;    //this is the number of the page.
bool notFound = true; //Indicates whether the element is found or not.
string search = "Non-Clinical 3";
IList<HtmlTableCell> myList = ActiveBrowser.Find.AllByTagName<HtmlTableCell>("td");
while (notFound)
{
   foreach (HtmlTableCell item in myList)
   {
      if (item.InnerText.Contains(search))
      {
       //Click, edit, verify
       Log.WriteLine("I have found it");
       notFound = false;
       //if you need to find and click on the link
       HtmlAnchor link = Find.ByExpression<HtmlAnchor>("tagname=a","TextContent=" + search.ToString());
       link.Click();
         break;
       }
    }                  
       if (notFound == false)
       {
         break;
        }
    page++;
    // Find the link for the next page and click on it.
    HtmlAnchor a = Find.ByExpression<HtmlAnchor>("tagname=a", "InnerText=" + page);
    a.Click();
}

You might also find useful reading our documentation about Element Identification when you are working with code.

I hope this helps.
Regards,
Velin Koychev
Telerik
Free summer webinars on advanced web automation tactics hosted by Jim Holmes & Adam Goucher.
Reserve your seat today!
0
Joseph
Top achievements
Rank 1
answered on 10 Jul 2013, 08:18 AM
Hi, im sorry to be a pain but this still doesnt seem to work the way i expect, i am using the code you have provided (thank you again) with one change: string search = "Non-Clinical 1".

the reason i search for non-clinical 1 is because it appears on the second page of the gridview, if i search for anything between 'non-clinical 16 - 2, it works as it should, it even clicks on the correct link, but like before it still does not change pages and therefore errors and stops the test,  i need it to search the entire gridview until it finds the correct record e.g. if not on page 1, change to 2, if not on page 2 change to 3 etc

i have attached another fiddler with the new code, i have also attached a document with instructions on logging in and finding the gridview
0
Velin Koychev
Telerik team
answered on 15 Jul 2013, 01:43 PM
Hi Joseph,

I think I found where the problem is. You should change this line of code:

if (item.InnerText.Contains(search))
to this one:
if (item.InnerText.Equals(search))
The reason why it fails is because "Non-Clinical 1" is contained in "Non-Clinical 10", but on the following lines it cannot find a proper link to click on. 

Let me know if this works.

Regards,
Velin Koychev
Telerik
We've released our first-ever public Test Studio BETA! Download the BETA, install it,
and send us your feedback! Expires mid-August!
0
Joseph
Top achievements
Rank 1
answered on 25 Jul 2013, 08:24 AM
Hi Velin,

I have been away for a week so sorry about the delay in getting back to you, Im sorry to say that this new code doesnt seem to correct the probelm completely.

again if i search for a value on the first page the test locates and click it successfully but if i try and find something on the 2nd or 3rd page it just seems to ignore it and fails the test, it is however changing pages now, i can see the gridview changing from 1 > 2 > 3, but it never actually locate the string i am searching for.

[CodedStep(@"New Coded Step")]
        public void WebTest_CodedStep()
        {
            ActiveBrowser.RefreshDomTree();
             
            int page = 1;    //this is the number of the page.
            bool notFound = true; //Indicates whether the element is found or not.
            string search = "Clinical 12";
            IList<HtmlTableCell> myList = ActiveBrowser.Find.AllByTagName<HtmlTableCell>("td");
            while (notFound)
            {
               foreach (HtmlTableCell item in myList)
               {
                  if (item.InnerText.Equals(search))
                  {
                   //Click, edit, verify
                   Log.WriteLine("I have found it");
                   notFound = false;
                   //if you need to find and click on the link
                   HtmlAnchor link = Find.ByExpression<HtmlAnchor>("tagname=a","TextContent=" + search.ToString());
                   link.Click();
                     break;
                   }
                }                 
                   if (notFound == false)
                   {
                     break;
                    }
                page++;
                // Find the link for the next page and click on it.
                HtmlAnchor a = Find.ByExpression<HtmlAnchor>("tagname=a", "InnerText=" + page);
                a.Click();
            }
             
        }
    }

I have attached a fiddler of the latest test.
0
Velin Koychev
Telerik team
answered on 25 Jul 2013, 01:25 PM
Hello Joseph,

I apologize for the mistake. I had some issues with your previous fiddler trace, so I was not able to fully test the previous solution. This time I was able to run it and I reproduce the issue. 

In order to fix it, y
ou just need to move this two lines of code inside the while loop:

ActiveBrowser.RefreshDomTree();
IList<HtmlTableCell> myList = ActiveBrowser.Find.AllByTagName<HtmlTableCell>("td");

Now the List of cells will be updated every time the page is changed. 
So, the code you need for your task is:
 
int page = 1;    //this is the number of the page.
bool notFound = true; //Indicates whether the element is found or not.
string search = "Clinical 12";
 
while (notFound)
{
   ActiveBrowser.RefreshDomTree();
   IList<HtmlTableCell> myList = ActiveBrowser.Find.AllByTagName<HtmlTableCell>("td");
   foreach (HtmlTableCell item in myList)
   {
      if (item.InnerText.Equals(search))
      {
       //Click, edit, verify
       Log.WriteLine("I have found it");
       notFound = false;
       //if you need to find and click on the link
       HtmlAnchor link = Find.ByExpression<HtmlAnchor>("tagname=a","TextContent=" + search.ToString());
       link.Click();
         break;
       }
    }                
       if (notFound == false)
       {
         break;
        }
    page++;
    // Find the link for the next page and click on it.
    HtmlAnchor a = Find.ByExpression<HtmlAnchor>("tagname=a", "InnerText=" + page);
    a.Click();
    }

I hope this helps.

Regards,
Velin Koychev
Telerik
We've released our first-ever public Test Studio BETA! Download the BETA, install it,
and send us your feedback! Expires mid-August!
0
Joseph
Top achievements
Rank 1
answered on 25 Jul 2013, 02:58 PM
Hi Velin,

Thank you very much, that works perfectly!

Jo
Tags
General Discussions
Asked by
Joseph
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Joseph
Top achievements
Rank 1
Velin Koychev
Telerik team
Share this question
or