Page 1 of 1

Looking for a GetText type - SOLVED

Posted: Wed Jun 27, 2012 9:53 pm
by benny28
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

Re: Looking for a GetText type

Posted: Wed Jun 27, 2012 11:20 pm
by Ciege
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") 

Re: Looking for a GetText type - SOLVED

Posted: Tue Jul 03, 2012 3:04 pm
by benny28
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