How can i specify object heirarchy in object repository

Apr 18, 2013 at 7:47 AM
How can i specify object heirarchy in object repository
some thing like

CUITe_WpfEdit customerSearchValue = customerSearch.Get<CUITe_WpfEdit>("Name=txtSearchValue");

can i have this in object repository like


customerSearch.customersearchvalue?

i may have an edit box inside two divs

i want to have them in object repository like

div1.div2.edit

does cuite object repository supports hierarchy ?
Coordinator
Apr 22, 2013 at 12:18 AM
Hi deepakguna,

This can be done by using classes.

Here is some sample test code:
using (TempFile tempFile = new TempFile(
@"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id=""div1"" >
            <div id=""div2"" >
                <input type=""text"" id=""edit""/>
            </div>
        </div>
    </body>
</html>"))
            {
                HtmlTestPage window = CUITe_BrowserWindow.Launch<HtmlTestPage>(tempFile.FilePath);

                window.div1.div2.edit.SetText("test");

                window.Close();
            }
Here is HtmlTestPage.cs:
using CUITe.Controls.HtmlControls;

namespace Sample_CUITeTestProject.ObjectRepository
{
    public class HtmlTestPage : CUITe_BrowserWindow
    {
        public HtmlTestPage()
            : base("test")
        {

        }

        public Div1 div1
        {
            get
            {
                return new Div1(this);
            }
        }
    }
}
Here is Div1.cs:
using CUITe.Controls.HtmlControls;

namespace Sample_CUITeTestProject.ObjectRepository
{
    public class Div1
    {
        CUITe_BrowserWindow Window;
        CUITe_HtmlDiv Div;

        public Div1(CUITe_BrowserWindow window)
        {
            this.Window = window;
            this.Div = this.Window.Get<CUITe_HtmlDiv>("id=div1");
        }

        public Div2 div2
        {
            get
            {
                return new Div2(this.Div);
            }
        }
    }
}
Here is Div2.cs:
using CUITe.Controls.HtmlControls;

namespace Sample_CUITeTestProject.ObjectRepository
{
    public class Div2
    {
        CUITe_HtmlDiv Div1;
        CUITe_HtmlDiv Div;

        public Div2(CUITe_HtmlDiv div1)
        {
            this.Div1 = div1;
            this.Div = div1.Get<CUITe_HtmlDiv>("id=div2");
        }

        public CUITe_HtmlEdit edit
        {
            get
            {
                return this.Div.Get<CUITe_HtmlEdit>("id=edit");
            }
        }
    }
}
The same architecture can be applied to wpf tests.
Apr 23, 2013 at 5:20 AM
hi i have a question in this
public class HtmlTestPage : CUITe_BrowserWindow
    {
        public HtmlTestPage()
            : base("test")
        {

        }
why we are calling base constructor with "test" parameter
Apr 23, 2013 at 5:35 AM
got it thank you! we are initializing with the title.
Coordinator
Apr 23, 2013 at 5:37 AM
CUITe_BrowserWindow has a constructor that takes a string parameter to use for the browser window title.
May 3, 2013 at 7:28 AM
did you implement this TempFile class?

Can you share the code?

TempFile tempFile = new TempFile
Coordinator
May 3, 2013 at 7:50 AM
TempFile.cs is part of Sample_CUITeTestProject in the "Source Code" (tab).

Here is a link to it, from commit 25457.
May 3, 2013 at 10:04 AM
Thank you!

We have a problem in this way.

following will work,
 window.div1.div2.edit.SetText("test");
but

window.div1.div2.
or
window.div1.


will not give any of the object's property or method
Coordinator
May 4, 2013 at 1:16 AM
Hi deepakguna,

Which properties or methods are you expecting?

Since div1 and div2 are custom classes, you will have to provide the properties and methods yourself.

You can try to change Div1 and Div2 so that they inherit from CUITe_HtmlDiv and maybe that's what you had expected?
May 6, 2013 at 3:44 AM
I am expecting to use the properties of CUITe_HtmlDiv. Thank you Icnocop inheriting will solve the problem.
May 9, 2013 at 4:08 AM
Hi Icnocop

I tried inherting Cuite_HTMLDIV

but the results are
window.div1.div2.edit.exists => true


window.div1.div2.exists => false

window.div1.exists => false


It is unable to find the div control
Coordinator
May 9, 2013 at 4:23 AM
Hi deepakguna,

Can you share your test and object repository classes please?

Thank you.
May 9, 2013 at 4:33 AM
Icnocop,

It is similar to what you have given in the example. Are you able to identify the div in the hierarchy?


May 9, 2013 at 4:33 AM
Hi Icnocop

It is similar to what you have given in the example. Are you able to identify the div in the hierarchy?
Coordinator
May 9, 2013 at 4:39 AM
Hi deepakguna,

The sample code does not compile with:
Assert.IsTrue(window.div1.div2.Exists);
Assert.IsTrue(window.div1.Exists);
May 9, 2013 at 4:45 AM
It will if you inherit the Div1 class from Cuite_HTMLDIV
Coordinator
May 9, 2013 at 5:00 AM
Hi deepakguna,

I cannot reproduce your issue.

Here is some sample test code that works without issue:
            using (TempFile tempFile = new TempFile(
@"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id=""div1"" >
            <div id=""div2"" >
                <input type=""text"" id=""edit""/>
            </div>
        </div>
    </body>
</html>"))
            {
                HtmlTestPage window = CUITe_BrowserWindow.Launch<HtmlTestPage>(tempFile.FilePath);

                window.div1.div2.edit.SetText("test");

                Assert.IsTrue(window.div1.div2.edit.Exists);
                Assert.IsTrue(window.div1.div2.Exists);
                Assert.IsTrue(window.div1.Exists);

                window.Close();
            }
HtmlTestPage.cs:
public class HtmlTestPage : CUITe_BrowserWindow
    {
        public HtmlTestPage()
            : base("test")
        {

        }

        public Div1 div1
        {
            get
            {
                return this.Get<Div1>();
            }
        }
    }
HtmlTestPage.Div1.cs:
public class Div1 : CUITe_HtmlDiv
    {
        public Div1()
            : base("id=div1")
        {
        }

        public Div2 div2
        {
            get
            {
                return this.Get<Div2>();
            }
        }
    }
HtmlTestPage.Div2.cs:
public class Div2 : CUITe_HtmlDiv
    {
        public Div2()
            : base("id=div2")
        {
        }

        public CUITe_HtmlEdit edit
        {
            get
            {
                return this.Get<CUITe_HtmlEdit>("id=edit");
            }
        }
    }
What error do you get?
What does your code look like?
May 9, 2013 at 5:02 AM
I dont get error but

window.div1.div2.Exists and window.div1.Exists gives me false
Coordinator
May 9, 2013 at 5:21 AM
So what's different between your code and what I pasted?

Thank you.
May 9, 2013 at 11:58 AM
There is no difference

do you get true for window.div1.div2.Exists ?
Coordinator
May 9, 2013 at 5:02 PM
Yes, the test passes.
Assert.IsTrue(window.div1.div2.edit.Exists);
Assert.IsTrue(window.div1.div2.Exists);
Assert.IsTrue(window.div1.Exists);
What's different between your HTML code and what I pasted?
May 10, 2013 at 4:55 AM
I have emailed you my object repository class
May 10, 2013 at 5:24 AM
The difference is

you are doing like
public class Div1 : CUITe_HtmlDiv
    {
        public Div1()
            : base("id=div1")
        {
        }
...
where as my code looks like `
  public class Div2
    {
        CUITe_HtmlDiv Div1;
        CUITe_HtmlDiv Div;

        public Div2(CUITe_HtmlDiv div1)
        {
            this.Div1 = div1;
            this.Div = div1.Get<CUITe_HtmlDiv>("id=div2");
        }
.....
`
May 10, 2013 at 6:11 AM
I got the problem resolved, once i initiate constructor with base (cuite_htmldiv) class constructor with search string.

Thank you