How can I parameterize property value in the Object Repository?

Mar 22, 2012 at 10:03 AM

Hi,

I am new to CodedUI Test and CUITe as well (and I'm not a developer)  and would like to ask if how can I parameterize property values in the object repository classes.

See sample below for reference of what I want to do:

namespace Project_CodedUI.Object_Repository
{
    public class Google : CUITe_BrowserWindow
    {
        public new string sWindowTitle = "Google";
        public CUITe_HtmlEdit txtHanapin = new CUITe_HtmlEdit("Id=lst-ib");
        public CUITe_HtmlSpan spntest = new CUITe_HtmlSpan("InnerText=jessie"); 

        // I want to use the InnerText to have another value so that I can reuse it with other search text

        public CUITe_HtmlButton btn = new CUITe_HtmlButton("Name=btnG;Class=lsb;Name=btnG;InnerText= ;Value=Hanapin");
        public CUITe_HtmlHyperlink lnkTemp1 = new CUITe_HtmlHyperlink("Class=l;InnerText=Jessie - Wikipedia, the free encyclopedia");
    }

}

 

Let me know your thoughts, thanks!

Jessie

Coordinator
Mar 22, 2012 at 3:27 PM

Can you please elaborate a bit more? Did not understand your requirement.

-- Suresh Balasubramanian

Mar 23, 2012 at 4:08 AM

The property value in the line below is hard-coded to a certain value (jessie" for this sample), can I use the same object for another value (say "suresh")?

   public CUITe_HtmlSpan spntest = new CUITe_HtmlSpan("InnerText=jessie");

The problem is that, I cannot reuse the object for another value, I have to add another object repository for an html span with a different InnerText value.

Here is the TestMethod for your reference:

[TestMethod()]
        public void CodedUITestMethod1()
        {
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463

            CUITe_BrowserWindow.Launch("http://www.google.com.ph/");
            Google pageName = CUITe_BrowserWindow.GetBrowserWindow<Google>();

            pageName.txtHanapin.SetText("jessie"); //I can tweak this line to make it data driven
            pageName.spntest.Click(); //I cannot use this line to click a new value, it will still look for "jessie" because that was defined in the object repository
            pageName.btn.Click();
            pageName.lnkTemp1.Click();

        }

Hope this helps.

 

Thanks!

- Jessie

Mar 23, 2012 at 9:45 AM

The following added lines (in bold) worked:

pageName.txtHanapin.SetText("suresh");
pageName.spntest.SetSearchProperty("InnerText", "suresh");
pageName.spntest.Click();
pageName.btn.Click();
pageName.lnkTemp1.SetSearchProperty("InnerText", "Mohinder Suresh - Wikipedia, the free encyclopedia");
pageName.lnkTemp1.Click();

Thanks :)
- Jessie

Apr 25, 2012 at 3:22 PM

Thanks Jessie! I was trying to fight the same situation. Thanks for sharing what you figured out.