Write attribute value to Log with Attribute(RepoItemInfo)?

Class library usage, coding and language questions.
mats
Certified Professional
Certified Professional
Posts: 23
Joined: Tue May 18, 2010 12:58 pm

Write attribute value to Log with Attribute(RepoItemInfo)?

Post by mats » Fri Nov 26, 2010 2: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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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

Post by Support Team » Mon Nov 29, 2010 6: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 ("@[email protected]") 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
.
Image

mats
Certified Professional
Certified Professional
Posts: 23
Joined: Tue May 18, 2010 12:58 pm

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

Post by mats » Tue Dec 07, 2010 10: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 ("@[email protected]") 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: " + "@[email protected]");
	Validate.EnableReport = true;
}
catch (RanorexException e)
{
    Report.Info("Expected RanorexException occured: " + e.ToString());
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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

Post by Support Team » Tue Dec 07, 2010 9: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
.
Image

mats
Certified Professional
Certified Professional
Posts: 23
Joined: Tue May 18, 2010 12:58 pm

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

Post by mats » Fri Dec 10, 2010 1: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'!

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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

Post by Support Team » Fri Mar 11, 2011 11:00 am

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
.
Image