Looking for a GetText type - SOLVED

Ask general questions here.
benny28
Posts: 34
Joined: Thu May 31, 2012 4:48 pm
Location: London
Contact:

Looking for a GetText type - SOLVED

Post by benny28 » Wed Jun 27, 2012 9:53 pm

Hey All

I want to extract the value of an item within a table, and compare it to my expected value.

I can use: Validate.Equals("myXpath", "1234") to compare both, but "myXpath" only return the Xpath (which is fair enough : ) ie. Actual is "myXpath" Expected is 1234

I'm thinking a library type must exist (similar to Selenium) like GetText and would fit into the about example code as: Validate.Equals(GetText("myXpath"), "1234")
and giving my a result as: Actual is 1234 Expected is 1234

I have been looking through the library list but have not found it yet :)
http://www.ranorex.com/Documentation/Ra ... anorex.htm
Last edited by benny28 on Tue Jul 03, 2012 3:04 pm, edited 1 time in total.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Looking for a GetText type

Post by Ciege » Wed Jun 27, 2012 11:20 pm

Something like this?
Since I don't know your element type, I used a placeholder called MyElementType.

Code: Select all

Ranorex.[MyElementType] MyElement = myXpath;
String MyText = MyElement.Text;
Validate.Equals(MyText, "1234") 
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

benny28
Posts: 34
Joined: Thu May 31, 2012 4:48 pm
Location: London
Contact:

Re: Looking for a GetText type - SOLVED

Post by benny28 » Tue Jul 03, 2012 3:04 pm

I had to get one of my Dev's to look at this for me as it was not as straight forward as I would have imagined.
Note we are working on a WPF application.

I have a dedicated Extensions class which I added:

Code: Select all

namespace Extensions

public static object GetWpfValue(this string ranorexPath, string attributeName)
        {
            var path = new RxPath(ranorexPath);
            var element = ElementEngine.Instance.RootElement.Find(path).FirstOrDefault();
            if(element == null) return new object();
            var value = element.GetAttributeValue(attributeName);
            return value;
        }

In my test script I simply call:

Code: Select all

Validate.AreEqual(MainScreen.GetWpfValue("Text"), "TextToValidate");
Works like a charm :D