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

String Concatenation Issue.

4 Answers 125 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
tapan
Top achievements
Rank 1
tapan asked on 22 Jul 2011, 11:24 AM

Hi Team,

I am stuck in the following area since couple of days.

We are implementing Keyword framework with Test Studio and we are facing few issues while implementing the silver light Keywords.

In our excel sheet we are passing the Parent object before accessing the underlying object in a particular page.

 

Now to access the Parent element we need to create a string as shown below and execute it.

But we are unable to execute the string or know how to create proper string.

 

Pages + "." + pageName + "." + Find.ByName<HtmlInputText>(objID).Text = inputData;

 

In Visual studio it is giving error as “An object reference is required for non static field method or property “ArtOfTest.webAii.Core.Find.ByName<TControl>(String)”

Please let us know how to resolve this issue.We tried several ways by referring samples posted in the net,
e.g. http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/f248d774-0918-4f68-a0c6-23aa29a7ae29
But after doing any modifications @ above link/code we are not able to execute it successfully.

Please help or let us know if there is some other way to resolve the issue.

Regards,

Tapan

4 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 26 Jul 2011, 03:29 PM
Hi Tapan,

The last part of your code looks fine "Find.ByName<HtmlInputText>(objID).Text = inputData;".
The error occurs because of this expression "Pages + "." + pageName +". Unfortunately our Pages object cannot be used this way.

As an alternative the Find object is a property off of the "Browser" object : "Manager.ActiveBrowser.Find.ByName()", so please try to use it as it's shown in this example:
// Launch a browser instance
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
  
// The active browser
ActiveBrowser.NavigateTo("http://www.google.com");
  
// Find the google search box and set it to "Telerik";
Find.ByName<HtmlInputText>("q").Text = "Telerik";
Hope this helps!

Best wishes,
Plamen
the Telerik team
Check out the Test Studio roadmap to find out more about the new performance testing functionality coming in our R2 2011 release this September!

Have you looked at the new Online User Guide for Telerik Test Studio?
0
tapan
Top achievements
Rank 1
answered on 26 Jul 2011, 03:59 PM
Hi Plamem,

Thanks for your reply.

Unfortunate I even missed the 'HtmlInputPassword' issue, please look below the function which is invoked for SetText or
basically typing a message in a text box.
Now for google we need to mention  " HtmlInputText" but in our application we need to mention "HtmlInputPassword" in case if password field has to be typed.
e.g.
1.   Pages.PassportSignIn.UsernameText.Text = "tapan@xyz.com";
Here we will be reading the following from Excel a. PassportSignin, b. UsernameText

2. myManager.ActiveBrowser.Find.ByName<HtmlInputText>(objID).Text = inputData;
Here we will be reading the HTMLINPUTText, objID, inputtData from Excel and replace by the actual object type.

3. For few SilverLight objects there is no property displayed in the DOM it gives only the UID which gets changed on every login.
   We tried pasing XAML expression by using ByExpression method but its not working.

Meaning if we can't create the string for above 1-2 then for each function we need to create seperate methods whenever there is change in the <HTML....>control type. Just Imagine for all operation like click, settext, button etc we need to create seperate methods.
Please suggest us solution for above 3 points.

================
public void setText()
        {
            try
            {
               if (objID.ToUpper() == "PASSWORD")
                {
                    STEPForTestStudio.myManager.ActiveBrowser.Find.ByName<HtmlInputPassword>(objID).Text = inputData;
                }
                else
                {
                    STEPForTestStudio.myManager.ActiveBrowser.Find.ByName<HtmlInputText>(objID).Text = inputData;
                }
                appendResult("Successfully inserted value '" + inputData + "' in '" + objID + "' text box.");
                debugLog.writeLog("Execution Passed. Keyword = 'SETTEXT'" + ", Object Name='" + objID + "'.Successfully inserted value '" 
                 + inputData + "' in '" + objID + "' text box.");
                stepResult = true;
===================================

We did earlier POC using TestComplete and we found that we were able to form a string using the following expression, Refer the same SetText function we created usingTestComplete.
Here Processname, pagename, objid are passed from Excel sheet.
------------------
TestComplete
public void setText()
        {
           if (Connect.Aliases[processName][pageName][objID]["Exists"])
           {
               Connect.Aliases[processName][pageName][objID]["SetText"](inputData);
               appendResult("Successfully inserted value '" + inputData + "' in '" + objID + "' text box.");
               debugLog.writeLog("Execution Passed. Keyword = 'SETTEXT'" + ", Object Name='" + objID + "'.Successfully inserted value '" + inputData + "' in '" + objID + "' text box.");
               stepResult = true;
           }
----------------

Regards
Tapan
0
Cody
Telerik team
answered on 28 Jul 2011, 10:46 PM
Hello Tapan,

There is a way to do this through Reflection. It's a little bit complicated. But for example, let's say i want to set the password of the password element shown in the attached screenshot. You can do this with this code:

object thePage = Pages.GetType().GetProperty("GmailEmailFromGoogle").GetValue(Pages, null);
object theElement = thePage.GetType().GetProperty("PasswdPassword").GetValue(thePage, null);
HtmlInputPassword passwordField = (HtmlInputPassword)theElement;
passwordField.Text = "myPassword";

Notice how I'm passing in strings for the different nodes taken from Elements Explorer. Hope this helps.

I have filed a feature request to make this easier. You can follow it here.

Regards,
Cody
the Telerik team
Check out the Test Studio roadmap to find out more about the new performance testing functionality coming in our R2 2011 release this September!

Have you looked at the new Online User Guide for Telerik Test Studio?
0
mints
Top achievements
Rank 1
answered on 02 Aug 2011, 04:39 AM
Hi Cody, Plamem

Many Thanks for logging the issue!
Am hoping to get the build soon as it is gonna make my life easier.

Will try the below solution and get back to you in case i find any more issues.

Thanks
Tapan
Tags
General Discussions
Asked by
tapan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
tapan
Top achievements
Rank 1
Cody
Telerik team
mints
Top achievements
Rank 1
Share this question
or