> --
> You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
> To post to this group, send email to selenium-...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-develo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-developers?hl=en.
>
>
You'll have to excuse my lack of Se1 experience, but could you explain
the use case for this? What's the benefit of having this logic in the
browser as opposed to in your test code (i.e. Ruby)?
Performance. For e.g. if you have a table with lots of rows & columns
& you want to read that information - it is far easier & actually
faster to just offload that to user-extensions & have JavaScript
process that information & send it over the wire. All of this can be
achieved in a single call. Otherwise you'll have to do multiple calls
to get the same information. Of course, you could probably grab the
source from the page, send it over to your test code & process it
there. But I think using user-extensions is a much cleaner solution.
In my case, we use user-extensions quite a bit to add our own custom
commands like getCSSCount etc, besides some other hacks we did to
improve IE performance.
--aditya
The only reason why I'm now looking
at Selenium 2 is because I need my scripts to run against IE9 and
Firefox 4, and only v2 handles both.
besides some other hacks we did to
improve IE performance.
Excellent!! That's definitely great to know. How did you get IE9 and
FF4 to run with Selenium 1? I'm running into errors on my end when
using the selenium RC server.
Mike
On Feb 17, 10:23 pm, Santiago Suarez Ordoñez <santi...@gmail.com>
wrote:
> On Fri, Feb 18, 2011 at 12:00 AM, MikeC <michael.lee.co...@gmail.com> wrote:
> > The only reason why I'm now looking
> > at Selenium 2 is because I need my scripts to run against IE9 and
> > Firefox 4, and only v2 handles both.
>
> I'm all in to find out a solution to make Selenium 2 support needs like
> yours, but just to clarify, I have both IE9 and FF4 working with Selenium 1.
> I tested it with version 2.0a7 and both later betas all of them work just
> fine (big win for JS atoms and free browser support!).
>
> Santi
User extensions seem to fall into one of a handful of categories:
* Adding new element locating mechanisms
* Adding new commands.
So far in this discussion, these categories have been bundled
together. That's unfortunate, because the way that they're handled
differs.
The first use case, that of adding new element locating mechanisms, is
quite often a generalization of a specific requirement, which is to
somehow hook into the JS library used within the rest of the
application (typically jquery) In the case where the required library
is already loaded by the app, it's enough to just use the
JavascriptExecutor. There's no loss of efficiency, and you can return
web elements.
It should be noted that one of the reasons why custom locators are
used in selenium is that it can be hard to identify and reference
elements from one another. In the case of finding the third cell in
the second row of a table, a Selenium 1 user would have faced either a
complex xpath or a custom locator. The same thing using the webdriver
APIs would look like:
WebElement table = driver.findElement(By.id("table"));
WebElement row = table.findElements(By.tagName("tr")).get(1);
WebElement cell = row.findElements(By.tagName("td")).get(2);
Put another way, the newer API quite often makes it easy to avoid
needing a custom locator in the first place. Better yet, since you can
now keep a reference to the element, rather than looking it up every
time you call it, the cost of extra calls to do the initial find can
often be ameliorated very quickly (in this case, within about one or
two method calls)
The second use case (adding more commands) is handled by the fact that
webdriver offers an API. New methods and commands can generally be
built using the primitives offered by the driver. For an example of
this in action, take a look at the Select class in the support
package. This models a SELECT tag, and allows a test to interact with
one in an efficient way. The first version of this implemented a very
simple approach, and as we identified bottlenecks and issues, this
approach was refined. The nice thing is that the user-facing API
hasn't changed during this refinement.
In my experience with several very large projects, moving to the new
APIs has resulted in clearer code and faster test times, even when
replacing custom user extensions.
Regards,
Simon
Here you go - http://www.ivaturi.org/home/hackingseleniumtoimproveitsperformanceonie.
NOTE - this is not necessarily a universal hack, but two other folks
that have tried this approach have told me that it did improve
performance for them dramatically.
--aditya
In my case, I typically end up with tables with over few hundred rows
rather frequently (and annoyingly might I add). And the way I reduce
my overhead is by writing a simple JavaScript routine that uses XPath
with "context" nodes in user-extensions. If I'm not wrong, your above
given example does the same thing, i.e. "WebElement table" is your
context node. This still requires me to make further calls to Selenium
to get rest of the nodes (rows and eventually table cells). On the
other hand, by offloading the processing to user-extensions, I always
end up with just one call. The user-extension I wrote, creates a JSON
representation & sends over the final table structure & data to my
code. I haven't really created a custom locator per se, but rather
reduced the chatter between Selenium & my test code.
AFAIK the concept of user-extensions provides flexibility & options
for users and definitely allows us to "hack" without actually
recompiling RC, which to me is a very big plus.
--aditya
Here you go - http://www.ivaturi.org/home/hackingseleniumtoimproveitsperformanceonie.
NOTE - this is not necessarily a universal hack, but two other folks
that have tried this approach have told me that it did improve
performance for them dramatically.
At a minimum, I have urged Simon that if we're going to tell people to
inject JavaScript in to the page, we need to provide some sort of
callback hook to notify the end user when a new page loads (so that
they know to inject it again). Simon - We don't yet have that, AFAIK?
But still, we can't have a solid backwards compatibility story until
we address user-extensions head on. I run in to folks who use
user-extensions all the time. Simon clearly doesn't use them or prefer
them, but part of the Selenium 2 story included a strong commitment to
backwards compatibility, so I want us to at least try to honor that
and potentially try to really understand users like Mike and see if we
can fit them in to Selenium 2 in a way that is more than just
compatibility.
I don't want this conversation to fade away like our user-extension
discussions have in the past but I also don't want to go make
suggestions since I know I won't be the one to code them. Hoping that
Simon and Mike can keep the healthy discussion going, but that we can
see some input from some of the other devs.
Patrick
Patrick
http://code.google.com/p/selenium/issues/detail?id=71
It's never been high on my list of priorities for a couple of reasons.
Firstly, because, as pointed out, I already use a different level of
abstraction, secondly because I already know when I expect a page load
to happen and can therefore inject pieces efficiently as needed.
Simon
I appreciate your point here, but I've run in to a lot of cases where
I don't have enough information to expect a page load to happen (ie:
I'm waiting on a page for an external event to cause a page to
reload). I'm glad that there is an issue for this and I hope it gets
addresses eventually, though I understand it probably makes things a
bit more complex.
That all said, wondering what Mike thinks about all this - would the
ability to check for page load events and then inject in JS address
his core concern? Could that be a viable path for users of
user-extensions?
Patrick
Simon
-adam
> Sounds like I need to write up how to migrate from Selenium 1 to
> Selenium 2. As a hint, take a look at switching "DefaultSelenium" for
> "WebDriverBackedSelenium"
>
> Simon
>
> On Fri, Feb 18, 2011 at 11:43 PM, RamMan<mike....@eloqua.com> wrote:
>> I have the distinction of being the first user of MikeC's Lebowski
>> framework which by the way I highly recommend. Lebowski (available as
>> a Ruby Gem) is an engineering marvel and the user-extensions.js file
>> clocks in at over 2k SLOC. Firefox 4 RC is due at the end of the
>> month. Since the Selenium 2 migration path looks like a steep climb,
>> if you have a short path to getting FF4 and IE9 support under Selenium
>> 1 then I would be very grateful to also hear it.
>>
>> On Feb 17, 10:36 pm, Santiago Suarez Ordo�ez<santi...@gmail.com>
>> wrote:
>>>> Excellent!! That's definitely great to know. How did you get IE9 and
>>>> FF4 to run with Selenium 1? I'm running into errors on my end when
>>>> using the selenium RC server.
>>> I Don't want to derail this conversation much, the process was not long but
>>> definitely not fun.
>>> Let's do something, I promise I'll write the process in detail in Sauce
>>> Labs' blog<http://saucelabs.com/blog> next friday!
>>> Would that work?
>>>
>>> Santi
>>>
>>>
>>>
>>>
>>>
>>>> Mike
>>>> On Feb 17, 10:23 pm, Santiago Suarez Ordo�ez<santi...@gmail.com>
--
Se1’s user-extensions.js doesn’t appear to be an accidental property at all. There’s an entire chapter in the documentation about them (http://seleniumhq.org/docs/08_user_extensions.html), and judging from the number of hits on Google, they’re certainly not in rare use. In my experience and observation, the common use case is to implement some new in-browser testing capability, whether that’s a new command, a new kind of locator for existing commands, or additional safety checks. And it’s been part of RC since almost the beginning of RC.
As to page load detection, well, that’s an orthogonal issue. But I wouldn’t be surprised if the ability to inject some JavaScript early in the page-loading process would do the job for most of the people who need it – those who have AJAX applications and which are often based on a JavaScript framework that has a concept of “done loading” (e.g., Dojo’s addOnLoad(), jQuery’s ready(), YUI’s onDOMReady()) .
Ross
I've got as far as checking the lebowski code out of git so that I can
have an amble through it and give some concrete suggestions. For now,
some generalities will have to suffice.
There's a couple of avenues to explore. The first thing that we do
with the webdriver-backed selenium. In this case, we make use of the
closure compiler (though any minifier would work) to extract
individual methods that can be executed as standalone scripts. This
avoids the overhead of having to parse and deal with unnecessary
functions in the JS.
The second thing is to take advantage of the JS already in the app.
For example, a common request from users is to be able to use jquery
for finding elements. A vast number of sites already use jquery
(indeed, it's the desire to use existing locators that tends to drive
the "I'd like to use jquery" requests), so there's no need to inject
it into the page: a simple "executeScript" is all that's needed. This
mechanism is more useful when using the webdriver apis because
"executeScript" can take arguments (so no more string concatenation)
This second approach also hints at another alternative, which is to
make use of proxy that will inject the scripts into pages under test.
The BrowserMob proxy was spun out of the one in the selenium project,
and so might well be able to handle this use case.
Of course, there will still be problems to do with isolating the AUT
from the JS that's being executed. In this case, we might have to
explore browser-specific approaches such as making use of firefox or
chrome extensions. I guess that Safari can do the same thing too.
The final thing to do is to emulate the behaviour of Selenium 1. That
is, use JS to open a window separate from the AUT, and load the
equivalent of the user-extension into that. The load is done once for
the lifetime of the app. Having done this, however, you're going to be
constrained to abiding by the rules of the JS sandbox. This isn't too
onerous, as this limitation is already present for user-extensions.
So, there's some ideas. What are your thoughts?
Simon
Thanks for the replies. I've spent a (very short) bit of time looking
at the lebowski code. I'm wondering whether you've already come across
the Closure Compiler? It's a javascript compiler that takes JS as
input and outputs more JS. It provides a lot of the functionality of
something like JsLint, and it's what we use on the selenium project to
allow us to take nicely formatted and annotated JS and compress the
heck out of it. From my scan of the code, it looks like Lebowski could
work with this with some manageable changes.
That's a really long way of saying that the concern about chopping up
the JS need not be the problem you're suggesting.
http://closure-compiler.googlecode.com
Cheers,
Simon
Simon
-adam
Ross
Simon