CUITe and XML source

Sep 25, 2012 at 5:13 AM

Can I use CUITe to load the XML file which is generated by the source code of a web page?

Thank you.

Coordinator
Sep 25, 2012 at 6:35 AM

Hi selecao338,

I'm not sure I understand your question, can you give a more detailed example please?

What do the contents of the xml file have to do with Coded UI Test (enhanced) framework?

Do you plan on using as test data or ...?

Thank you.

Sep 25, 2012 at 6:40 AM

The source code of the website that I want to test like this:

<html>
<frameset>
    <frame id="FrameMenu">
    ....
    </frame>
    <frame id="FrameMain">
        <html>
            <head></head>
            <body>
                <div>....</div>
                <div>....</div>
                <div>....</div>
                <xml id="schedule" XMLDocument="[object]"/>
            </body>
        </html>
    </frame>
</frameset>
</html>

I want to access the xml file with id is "schedule" because the contents of that xml file have the ids of some controls. If I can read that xml file, I can get the ids of some controls. Then I can find those controls and run the tests.

Thank you.

Coordinator
Sep 25, 2012 at 7:29 AM

You can get the html of a web page as follows:

 

TestHtmlPage window = CUITe_BrowserWindow.Launch<TestHtmlPage>(CurrentDirectory + "/TestHtmlPage.html");

CUITe_HtmlDocument doc = window.Get<CUITe_HtmlDocument>();

string outerHtml = doc.UnWrap().GetProperty("OuterHtml").ToString();

 

You can also get the control definition as follows:

TestHtmlPage window = CUITe_BrowserWindow.Launch<TestHtmlPage>(CurrentDirectory + "/TestHtmlPage.html");

CUITe_HtmlButton btn1 = window.Get<CUITe_HtmlButton>("id=button1");

string controlDefinition = btn1.UnWrap().ControlDefinition;
You can create your own custom control wrapper by looking at the definition of CUITe_HtmlHeading1, so you can create one for the xml element for example.

Loading and parsing the html and\or xml is beyond the scope of this discussion forum and CUITe in general, but you can try using the System.Xml.XmlDocument class for example.

You can also make a generic http web request to download a file programmatically by using the System.Net.HttpWebRequest class.  You can see this link for an example:

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx

Coordinator
Sep 29, 2012 at 9:27 AM

I've just checked in an implementation of CUITe_HtmlXml specifically for the <xml /> tag so now you can do something like:

CUITe_HtmlXml xml1 = new CUITe_HtmlXml("id=schedule");

or

CUITe_HtmlXml xml1 = Get<CUITe_HtmlXml>("id=schedule");

or

CUITe_HtmlXml xml1 = parentContainer.Get<CUITe_HtmlXml>("id=schedule");

Oct 1, 2012 at 10:49 PM

Thank you so much.

I will try it.

Oct 2, 2012 at 1:37 AM

Hi,

I tried to use to find the CUITe_HtmlXml and it just works with this:

CUITe_HtmlXml xml1 = parentContainer.Get<CUITe_HtmlXml>("id=schedule");

But when I access to its properties, all of them are null. So how can I get the source of that xml file?

Thank you so much.

Coordinator
Oct 2, 2012 at 2:40 AM

Hi selecao338,

Have you looked at the properties of UITestControl returned by xml1.UnWrap() (and also its inherited properties)?

I don't have any experience with the xml element but it seems it is only really useful with JavaScript.

You can call the RunScript method on CUITe_BrowserWindow or CUITe_HtmlControl passing it some JavaScript code that will read\load\import the xml into the html page.

I recommend loading the xml in such a way that you can access it using the InnerText property of a control for example.

I've seen InnerText properties that contain a CDATA element that holds xml for example, but I'm not sure how to make that happen dynamically using JavaScript for example.

As recommended before, can you not make a generic http web request to download the xml file programmatically by using the System.Net.HttpWebRequest class?  You can see this link for an example: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx

Oct 2, 2012 at 3:26 AM
Edited Oct 2, 2012 at 3:26 AM

Hi,

I found the solution, I did like you said before:

 

CUITe_HtmlXml doc = window.Get<CUITe_HtmlXml>();

string outerXml = doc.UnWrap().GetProperty("OuterHtml").ToString();

Thanks for your help.

Dec 12, 2012 at 8:23 AM

Hello,

I am new to CUITe. My requirement is like. My page should automatically open and search the inner text for a particular id. say my page has a div element with id as div1. With this Div1 should get the inner text of that element. SO finally when I run the test I will only pass the link of my page and the control or element Id. Please help me out.

Above you have written,

TestHtmlPage window = CUITe_BrowserWindow.Launch<TestHtmlPage>(CurrentDirectory + "/TestHtmlPage.html");

CUITe_HtmlDocument doc = window.Get<CUITe_HtmlDocument>();

string outerHtml = doc.UnWrap().GetProperty("OuterHtml").ToString();

can you please tell me what is 'TestHtmlPage' ?

 

Coordinator
Jan 17, 2013 at 7:47 AM

TestHtmlPage is an object repository class.

It is defined in the latest source code in Sample_CUITeTestProject\ObjectRepository\TestHtmlPage.cs