18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
_getText() returns different results across browsers
Hi,
I'm using sahi with behat to test a web app (primarily with chrome). Recently, I wanted to test the web app with firefox too, but as of now, some tests that passed with chrome don't pass with firefox.
It seems that the getText() method, which is used in "I should see" behaviour of behat does not return the same result when launched on chrome and firefox.
Chrome (16.0.912.63) returns only visible text on the page
Firefox (9.0.1) returns all text strings on the page, visible or not (meaning : css "display:none" text, all strings in select elements...).
Moreover, text in Chrome that has a "text-transform=uppercase" is returned as uppercase in getText, but in firefox, it's lowercase (as of now, i've bypassed this issue by using a regexp).
Do you know any method to get the same behaviour in all browsers (preferably getting firefox act as chrome)?
Thanks,
I'm using sahi with behat to test a web app (primarily with chrome). Recently, I wanted to test the web app with firefox too, but as of now, some tests that passed with chrome don't pass with firefox.
It seems that the getText() method, which is used in "I should see" behaviour of behat does not return the same result when launched on chrome and firefox.
Chrome (16.0.912.63) returns only visible text on the page
Firefox (9.0.1) returns all text strings on the page, visible or not (meaning : css "display:none" text, all strings in select elements...).
Moreover, text in Chrome that has a "text-transform=uppercase" is returned as uppercase in getText, but in firefox, it's lowercase (as of now, i've bypassed this issue by using a regexp).
Do you know any method to get the same behaviour in all browsers (preferably getting firefox act as chrome)?
Thanks,
Comments
Am I the only one affected ?
To be more precise, this call :
_sahi._getText(_sahi._byXPath("//html"))
doesn't return the same text in chrome and firefox (only visible text in chrome, and all text in the page in firefox).
I've also tested sahi pro with the same results.
Can you post a html snippet which we can use to reproduce this behaviour? Can you also specify what you are trying to do? Sahi has a different way of looking at things, and we may be able to suggest a different way.
XPaths are something we stay away from, so cannot help on that.
Regards,
Narayan
Thanks for your answer.
I'm using behat to test my web app (it's like cucumber, but for php)
It makes it easy to write some scripts to verify be behaviour of a web app.
Ex :
Given I am on "/some/page"
When I fill "username" with "foo"
And I fill "password" with "bar"
And I press "login"
Then I should see "welcome foo"
In behat, the "I should see" part of the script internally uses "_sahi._getText(_sahi._byXPath("//html"))" to fetch the text available on the page so that behat can check wheter the text is available anywhere on the page.
However, there is a big difference between Webkit and Firefox/IE that is quite easy to see.
Go to a simple web site (let's say craigslist.com) and just execute _sahi._getText(_sahi._byXPath("//html")) is js console of both firefox and chrome.
Let alone the fact that firefox returns the sahi debug cdata. Just compare the 2 string results.
You'll see that in Chrome, only visible text is returned, whereas in firefox there is much more text (even invisible text is returned).
We used to test with behat only in chrome. As we recently wanted to extend our tests to other browsers, we saw that many tests where misbehaving and found out it was because of this difference.
Isn't there anything I can do to obtain the same behaviour everywhere ? What would you suggest ?
Regards
This issue has been reported to Behat/Mink's developer, and he says that this is a bug in Sahi. See github.com/Behat/Mink/issues/186
The website we are testing uses text-transform:uppercase extensively. The way it currently stands, we would need to write two sets of tests - one for Firefox and one for WebKit browsers. This is unacceptable.
Is there any plan to address this issue?
Waiting for a fix to this "issue", we managed to circumvent the case sensitive issue in 2 different ways (hopefully it'll prove useful to you).
1- Using a regular expression with a recent behat version (>=january 2012) The (?i) part is used to set a "case insensitive" flag for the regular expression function.
Please note that due to the fact that the tested string is interpreted as a regex, you have to be careful with special characters.
2- Using a custom context function (add it to your browserContext.php) Note that the use of iconv function was necessary so that diacritics are correctly evaluated (without it, uppercase accentuated letters were not transformed to lowercase).