Write attribute value to Log with Attribute(RepoItemInfo)? : Automation API

Write attribute value to Log with Attribute(RepoItemInfo)?

Class library usage, coding and language questions.

Write attribute value to Log with Attribute(RepoItemInfo)?

Postby mats » Fri Nov 26, 2010 3:27 pm

The Method Attribute(RepoItemInfo, String, Regex, String) can send a Message to the Log:

Validate.Attribute(RepoItemInfo, AttributeName, Regex, String2Log)

"{0}" is replaced by the name of the itemInfo object, "{1}" by the attribute name.

But what if the real attribute value should be logged?
How can I write the real attribute value (not the Regex) into the Log?

-> Feature request: "{2}" is replaced by the attribute value.
mats
 
Posts: 18
Joined: Tue May 18, 2010 1:58 pm

Re: Write attribute value to Log with Attribute(RepoItemInfo)?

Postby Support Team » Mon Nov 29, 2010 7:48 pm

mats wrote:How can I write the real attribute value (not the Regex) into the Log?
-> Feature request: "{2}" is replaced by the attribute value.

This feature is currently not available, mainly because not in all cases it is possible to get the actual value of the attribute, e.g. if the element corresponding to the repository item cannot be found. Anyway, I added a feature request for that placeholder; I guess in the case that the actual value cannot be obtained, we will then just use the empty string to replace the placeholder.

For now, there is another (internally used, non-documented) placeholder string ("@Validate.AttributeREASON@") that is replaced by the reason why a validation failed (or the empty string if the validation succeeds). I don't know if that is good enough for you at the moment :-)

Regards,
Alex
Ranorex Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Write attribute value to Log with Attribute(RepoItemInfo)?

Postby mats » Tue Dec 07, 2010 11:55 am

Thank you for this internal function.
But it is not exactly what I need.
For example I want to write the value of my titlebar into the Report, because therein is the Product Release String.
The placeholder string ("@Validate.AttributeREASON@") is replaced by the reason only if a validation failed. Is it possible to write this reason into an other string, or to start a validation without exception and without 'validation failure' in the Report?

This Example writes the whole exception string into the Report, but I need only the actual value:
Code: Select all
try
{
   Validate.EnableReport = false;
   Validate.Attribute(repo.Login_ARTS_Explorer.TitleLogin_ARTS_Explorer_3_x, "Text", new Regex("Value"), "Test2: " + "@Validate.AttributeREASON@");
   Validate.EnableReport = true;
}
catch (RanorexException e)
{
    Report.Info("Expected RanorexException occured: " + e.ToString());
}
mats
 
Posts: 18
Joined: Tue May 18, 2010 1:58 pm

Re: Write attribute value to Log with Attribute(RepoItemInfo)?

Postby Support Team » Tue Dec 07, 2010 10:58 pm

I think the easiest way to achieve that functionality right now is to write your own method performing the validation. The code for that method could look like the following:
object value = repo.MyText.Text; // get value by adapter property
value = repo.MyText.Element.GetAttributeValue("Text"); // value get by attribute name
string stringValue = Ranorex.Core.ValueConverter.ToString(value);
Validate.AreEqual(stringValue, regex, "Your message containing the attribute value '" + stringValue + "'.");

Regards,
Alex
Ranorex Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Write attribute value to Log with Attribute(RepoItemInfo)?

Postby mats » Fri Dec 10, 2010 2:44 pm

This code is working.

My problem was the fact that the Itemname in the Repository 'repo.MyText' was, but in the *.cs and *.UserCode.cs 'repo.MyTextInfo'. So I had to delete the suffix 'Info'!
mats
 
Posts: 18
Joined: Tue May 18, 2010 1:58 pm

Re: Write attribute value to Log with Attribute(RepoItemInfo)?

Postby Support Team » Fri Mar 11, 2011 12:00 pm

mats wrote:-> Feature request: "{2}" is replaced by the attribute value.

This feature will be available with Ranorex 3.0.1 (projected release date is end of March 2011).

Regards,
Alex
Ranorex Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests