Validating Link Title in Firefox

Ask general questions here.
Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Validating Link Title in Firefox

Post by Fergal » Tue Nov 25, 2014 3:59 pm

The test shown below, validates the title of the "link with title" on the http://www.ranorex.com/web-testing-examples/ web page.

Image

Full image shown here.

The XPath for the link title is:

Code: Select all

/tooltip[@text='link title']
The test runs fine and passes in IE, Chrome and Safari. However, it fails in Firefox. How can I get it to run successfully in Firefox?

Thanks!

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Validating Link Title in Firefox

Post by krstcs » Tue Nov 25, 2014 4:24 pm

What error are you getting on FF? Without that it's hard to know what is happening.

I would suggest that you not use the @text attribute for both the XPath and the validation of the text. If you have the the @text='link title' attribute in your XPath, Ranorex will not find the item if the text is different, so you could just use the Validate.Exists() method. Since @text can change, you should try using a different attribute to ID the element, if there is one.

My guess is that FF has something different for the XPath, and that you are getting a timeout because Ranorex can't find the element. Try using Spy to check the path on FF vs Chrome or IE and see what is different.


Also, please include the Ranorex version, Windows version, and technology of the SUT in any post where you are asking questions. This will help us know if there is a bug or other issue that is fixed/created by a specific version of Ranorex.
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Validating Link Title in Firefox

Post by Fergal » Tue Nov 25, 2014 4:52 pm

Thanks krstcs.

The error for the Firefox test run is as follows;
Attribute 'Text' of element for item 'Z_Ranorex_Web_Testing_ExampleRepository.LinkTitle.Self' does not match the specified value (Failed to find item 'Z_Ranorex_Web_Testing_ExampleRepository.LinkTitle.Self'. No element found for path '/tooltip[@text='link title']' within 30s.).
I'm using Ranorex V 5.2.020272, Windows 7 and Firefox 33.1.1.

I tried recording the test again, this time on Firefox, using the "T" hotkey to validate the link title / tooltip. The validation step doesn't record, it's as if Ranorex can't see tool tips in Firefox? Hence, I'm not sure how to get the XPath for the link title in Firefox.

Thanks again!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Validating Link Title in Firefox

Post by Support Team » Wed Nov 26, 2014 2:21 pm

Hello Fergal,

The RXPaths of the tooltips are not the same within the mentioned browsers. The tooltip from an element in Chrome can be found as a child from the Host-element, whereas the tooltip from an element within Firefox is a child of the Firefox form element
ToolTipFirefox.png
ToolTipChrome.png
Regards,
Robert
You do not have the required permissions to view the files attached to this post.

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Validating Link Title in Firefox

Post by Fergal » Wed Nov 26, 2014 6:03 pm

Thanks Robert,

How can I create a cross-browser test that will validate the text of that tooltip, in all four browsers (IE, Chrome, Safari and Firefox)?

I have a test that will work in all the browsers, except Firefox.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Validating Link Title in Firefox

Post by krstcs » Wed Nov 26, 2014 6:58 pm

Create two repo items, one for FF, the other for the rest.

In user code, do an if-then-else:

if (browser==FF) check the ff tooltip repo item...
else check the main tooltip item

EDIT: The easiest way to do it is to drop BOTH validations into the same recording module, one after the other. Select both lines and right-click. Select "Merge to User-code". Double-click the new "User-code" line and it will open up the editor. Just wrap the two actions (2 lines each) with the if and else, making sure to have the logic correct.
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Validating Link Title in Firefox

Post by Fergal » Thu Nov 27, 2014 11:42 am

Thanks very much krstcs, that's very helpful.
krstcs wrote:Create two repo items, one for FF....
How do I create the repo item for Firefox, given that I can't seem to get Spy to identify the tooltip? Or to put my question another way...

Support Team wrote:...Image
What would the XPath be for that?

Thanks again!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Validating Link Title in Firefox

Post by Support Team » Fri Nov 28, 2014 9:36 am

Hello Fergal,

Please use following path:

Code: Select all

/tooltip[@text='link title']
Regards,
Robert

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Validating Link Title in Firefox

Post by Fergal » Fri Nov 28, 2014 10:21 am

Thanks Robert, I've been trying that but get the error below:
Element for item 'Tooltip_in_Firefox' does not exist (Failed to find item 'Z_Ranorex_Web_Testing_ExampleRepository.Tooltip_in_Firefox'. No element found for path '/tooltip[@text='link title']' within 30s.).
My test looks like this:
Image

Link to full size image.

The test doesn't work when I use either the Tooltip_in_Firefox or Copy_of_Tooltip_in_Firefox repository items.

Do you know what I'm doing wrong?

Thanks again!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Validating Link Title in Firefox

Post by Support Team » Fri Nov 28, 2014 10:28 am

Hello Fergal,

Yes, the Firefox tooltip is recognized as a child from the Firefox form elment:
ToolTipFirefox.png
Therefore, the RxPath is the following:

Code: Select all

/form[@title='YourTitle']/tooltip[@accessiblename='link title']
Regards,
Robert
You do not have the required permissions to view the files attached to this post.

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Validating Link Title in Firefox

Post by Fergal » Fri Nov 28, 2014 11:06 am

Thank you Robert, the XPath below is working perfectly for me. I will try to get the conditional working now.

Code: Select all

/form/tooltip[@accessiblename='link title' and @visible='True']
Thanks again!

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Validating Link Title in Firefox

Post by Fergal » Tue Dec 09, 2014 3:48 pm

krstcs wrote:Create two repo items, one for FF, the other for the rest.

In user code, do an if-then-else:

if (browser==FF) check the ff tooltip repo item...
else check the main tooltip item

EDIT: The easiest way to do it is to drop BOTH validations into the same recording module, one after the other. Select both lines and right-click. Select "Merge to User-code". Double-click the new "User-code" line and it will open up the editor. Just wrap the two actions (2 lines each) with the if and else, making sure to have the logic correct.
I've done all of that and have a method in the code module that looks like this;

Code: Select all

 public void MergedUserCodeMethod()
        {
        	Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'Tooltip_in_Firefox'.", repo.Tooltip_in_FirefoxInfo);
            Validate.Exists(repo.Tooltip_in_FirefoxInfo);
        	Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Visible='True') on item 'LinkTitle'.", repo.LinkTitle.SelfInfo);
            Validate.Attribute(repo.LinkTitle.SelfInfo, "Visible", "True");          
        }
How do I get the if else to work? I have been trying variations such as the following, but can't get them to work.

Code: Select all

if(browser == Firefox) {
        	Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'Tooltip_in_Firefox'.", repo.Tooltip_in_FirefoxInfo);
            Validate.Exists(repo.Tooltip_in_FirefoxInfo);
        	} else {
        	Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Visible='True') on item 'LinkTitle'.", repo.LinkTitle.SelfInfo);
            Validate.Attribute(repo.LinkTitle.SelfInfo, "Visible", "True");
        	}
if(Browser == Firefox)

if($var_Browser == Firefox) // I have a variable for Browser names, called $var_Browser.

Thanks again!

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Validating Link Title in Firefox

Post by krstcs » Tue Dec 09, 2014 3:59 pm

The browser name is stored as a string, so you have to work with it as a string... "Firefox".

Code: Select all

if (browser == "Firefox") {
  //do stuff for FF here
} else {
  //do stuff for everything else here
}
Edit to Add: Also, you shouldn't use '$' in variable names in .NET. This is just what Ranorex uses in its domain specific language to signify a user variable in the front-end.
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Validating Link Title in Firefox

Post by Fergal » Tue Dec 09, 2014 4:25 pm

Thanks krstcs.
Also, you shouldn't use '$' in variable names in .NET. This is just what Ranorex uses in its domain specific language to signify a user variable in the front-end.
Yes, the "$" was added by Ranorex not by me.
The browser name is stored as a string, so you have to work with it as a string... "Firefox".
I've made that change, but my code, copied below, still isn't working. It seems to be an issue with the word "browser" in the if condition?

Code: Select all

if(browser == "Firefox") {
        		Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'Tooltip_in_Firefox'.", repo.Tooltip_in_FirefoxInfo);
            	Validate.Exists(repo.Tooltip_in_FirefoxInfo);
        	} else {
        		Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Visible='True') on item 'LinkTitle'.", repo.LinkTitle.SelfInfo);
            	Validate.Attribute(repo.LinkTitle.SelfInfo, "Visible", "True");
        	} // else

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Validating Link Title in Firefox

Post by krstcs » Tue Dec 09, 2014 8:07 pm

Without seeing all of your code I couldn't tell you what the problem is. You also haven't shown the error message.

My first guess would be that you haven't declared the variable "browser" or haven't assigned it the value from your test.

.NET doesn't know what "browser" means unless you tell it. It is a string, that contains the name of the browser being used by your DOM object, so you need to tell it that.

Code: Select all

string browser = repo.MyDomObject.Self.Browser;

if (browser == "Firefox") {...}

//or, the more efficient way, not instantiating an unnecessary object (string browser)...

if (repo.MyDomObject.Self.Browser == "Firefox") {...}
Remember, computers are stupid. (They're very FAST at being stupid, but they are still stupid...) They don't know anything you don't tell them. And they have to know EXACTLY what you want them to do and EXACTLY what you want them to do it to/with. So, you have to describe things to them before they can use them, and you have to then give them the logic to use.
Shortcuts usually aren't...