How does watin compare to selenium for testing IE? - selenium

My team has started to use selenium to do IE browser testing. One major sticking point is that selenium has a hard (read: seemingly impossible) time figuring out when a page has fully finished loading. We use a lot of javascript, a fair amount of AJAX, and a smattering of third party controls. Thus, it's hard to know when all of that activity has completed and the page is ready to test. Much of this code is legacy, so simply rewriting or refactoring the page is not an option -- it's a very large enterprisey app.
My main question is this: Is Watin any better in this regard? Does it have any sort of built-in mechanism for detecting when a page has fully loaded?
We unfortunately can't just wait for an element to become visible, which is the generally accepted practice for selenium. Often we are dealing with a scrolled list of dynamic elements and need to wait for the javacript to finish, as there is an indeterminate (to the test) number of elements on which we must wait.
Switching to another browser is simply not possible, we must find a solution that works with IE. I'm trying to decide if it's worth our time to investigate watin, or if we would just be trading one set of limitations for another.

I used WatiN for quite a while and have more recently made the switch to Selenium because I feel it actually handles the situation you explain better than WatiN does (has a 'wait' that can be created on the driver in Selenium WebDriver). However, I think it really ends up being a matter of opinion.
WatiN will only work well with IE, so you are limited to this and can't branch out into other browsers. Due to this, WatiN is made for IE, suggesting that you might have better success with it for IE.
As a side note, have you tried using Windows calls to check if a browser has finished loading? I believe this is possible? An the addition of XPath in Selenium can be rather useful, though slow with IE.
EDIT: Alternatively, couldn't you call some javascript to see when the javascript on the page has finished?
EDIT EDIT: Also this post covers a lot of comparisons and opinions.

Well as far as my work with WatiN goes it's easier than Selenium. We too have a lot of javascript, ajax - my solution for that is using
WebBrowser.Current.Div(ids.waitForBagGridToLoadIdentifier).WaitUntil("style", "display: none;");
to wait for a particular javascript to finish it's work. There is probably a similar approach for Selenium.

Related

Selenium Webdriver Java with TestNG & POM: Should we use explicit wait (ExpectedConditions) for all the web elements

In my project, the web application code is developed by a third party. The client does not know if ajax or other technologies are used which might load web elements at different times.
We are automating the testing of the web application using Selenium Webdriver with Java, TestNg, POM.
Will it be a bad practice to have explicit wait using ExpectedConditions for all the elements that we automate?
As of today (04September2022), we are running manual testing on the application to gauge which modules to automate first, and have noticed that the webpage elements (textboxes, links, buttons, dropdowns etc.) seemingly load at random times. Hence we are debating if we should use explicit wait for all the elements upfront, instead of a trial and error basis.
Will it be a bad practice to have explicit wait using ExpectedConditions for all the elements that we automate?
In my opinion, largely not. I often identify elements by waiting for them to be clickable; from the way you've worded your question, it sounds like this could work and more importantly, be helpful in terms of avoiding any ElementNotFoundException if you tell Selenium to simply grab that element without waiting.
Depending on your use case however, it may be that an element you're attempting to identify will never become clickable--or even visible or enabled, for that matter. In this case you could use the Expected Condition simply to wait for the element to be present.
An examination of the relevant Expected Conditions class (I'm not sure which language you're using, else I'd link it) will reveal to you exactly which explicit wait options you have at your disposal.
One more comment: are you testing a JavaScript-based frontend? If so I would recommend you consider Cypress, WebDriverIO, or Playwright, each of which waits much more intelligently for JS pages/elements to load properly.
Wow I haven't heard anyone say Ajax in a very long time. You can use explicit wait, or you can just poll for it. there's not really much difference since Webdriver wait just polls for things as well. Whatever you find to be simpler in other words since Java is doesn't have events.

Selenium RC architecture and Selenium WebDriver architecture differences

Hi I want differences between architectures of selenium RC and webDriver.
I read lot of functional differences but did not find anything for architecture differences.
If anyone can send/post links of differences that will really appriciate.
Thanks in advance
The difference is quite substantial.
Selenium RC works only using JavaScript for its every command. That means that everything you write is eventually translated into Javascript and run in the browser. This approach has several pros and cons - it should work the same way in every browser, but is limited to "same origin policy" and to JavaScript limitations.
http://seleniumhq.org/docs/05_selenium_rc.html#how-selenium-rc-works
WebDriver actually uses each browser's own and native API's to work with them. That means that it sometimes needs direct help from browser development team, sometimes fails on a new browser version release, sometimes behaves slightly differently on different browsers (but hey, on IE, js was also not the most reliable thing), but is a much stronger tool overall. It should be faster, it should allow for much more complex work without any js limitations.
http://seleniumhq.org/docs/03_webdriver.html#how-does-webdriver-drive-the-browser-compared-to-selenium-rc
Note that while Selenium RC has been oficially deprecated, the WebDriver is now being developed rapidly and it still suffers from several child-illnesses and is not in its full strength. That said, using WebDriver, you can do anything Selenium RC can do. And sometimes more. With an occasional minor bug.
here you can Selenium Webdriver Architecture
http://qeworks.com/selenium-webdriver-architecture/
you can also find diff. between RC and webdriver below
http://qeworks.com/difference-between-selenium-rc-and-selenium-webdriver/
Though there are many advantages of Page Project Model, some of them worth mentioning are :
Simple and clear page classes with sensible method names.
You can actually give the customize names to you methods. Like above so that you need not to keep anything in mind.
Just looking into the method name gives you all idea about the capabilities of the method.
Makes tests more readable. In comparison to above commands of selenium , where in you need to add all the commands in the tests scripts . in page object model you need to put method names. The methods which you have created according to your understanding of application so these methods name are more readable and easy to understand.
Stay [DRY]
Page object model believes in the principle of Do not repeat yourself.
Good support of tests, because everything is stored in one place.
Easy creation of new tests. In fact, tests can be created by a person not knowing the features of automation tools.
As I have actually implemented it in my project so definitely there are some flaws:
All locators should be kept in page class file.
And this abstraction leads to some chaos with in the Page Class file.
So you need to implement something like key word driven on top of Page Object Model so as to fully take the advantages.

A simple text based full web-page regression testing

My duty is to pick up and continue developing PHP website for a small sized business client. Project has no testing code. I want to quickly establish at least very basic regression testing for the backend of the site.
I need to test the full contents of the web page char to char. Must see the diff of failed tests.
I need to be able to set up cookies and GET/POST data.
Once every few days I am updating the local database from production database. I would like to then have an overview of failed tests and very quickly update my test suits so that everything is passing again.
Is using WatiN or Selenium a good idea? My local environment is Linux.
About Selenium (and only Selenium as I don't know WatiN) - it can only do what you can do in your broswer. It can click, type in fields, submit forms, take screenshots (that's a very good one), set up cookies (so yes to this one). You can always set up GET data through the URL. But I am not aware of any technique in Selenium that would allow you to set up POST data in any other way than navigating in a browser. Also, because the tests are in your browser, they are not particularly fast. E.g, on our product, a single thorough test with ~250 steps takes about 10 minutes on my computer to complete. Of course, you can always divide that between many computers using Selenium Grid. It's just more work.
To conclude it - I'd say yes, Selenium is good for your needs as there are so many ways to write a good test in it that everyone finds his style. It is good for quick checks, functionality affirmations, but also for full-scale tests etc. But if you want to do some really advanced stuff, then that's a job for a long time. Selenium offers so much functionality in so many different ways that it is definitely a full-time job to understand them and know how to use them.
Try Selenium-IDE for 20 minutes. It is just an addon for Firefox that can record your actions and then replay them. If you like what you see, go for it. If no, hire someone who will.
I'm not sure if I am too late here, but in regards to WatiN it is only IE based, so if you plan to use any other browser you are better off with Selenium WebDriver (though WatiN has some Firefox support). From what I have found (I have used both WatiN and Selenium) Selenium can achieve more low level interactions (also see Selenium Grid), but really I think it is dependant on what you are looking to achieve and personal preference. If you have time to write your own wrapper to interact with WatiN/Selenium you will find the tests themselves are rather quick to run. Also, the beauty of Automation is that once these tests are written you can run them and walk away while they complete.

Selenium vs. WebDriver, any obvious advantages?

I've moved from SeleniumRC to WebDriver for nearly two years. But I have to say that I haven't felt there's any obvious advantages for webdriver over rc.
Now I have 200+ test cases with C# driver against a website. But when I run them thoroughly for regression testing, I usually get 150 passed and 50+ failed/errored. After running failed test cases for the second time, many of them passed, only few of them were proven to be issues with the testing code.
As I can see it, sometimes WebDriver is really performing slowly, while I never met with such a situation when I was using SeleniumRC before.
As a result, I started to doubt the necessity to move from rc to webdriver, because it took much more time for me to verify errors and failures than before.
So my question is, are there any advantages for webdriver over rc to make it worth it to move from rc to webdriver? If so, can you please kindly tell me? Also, tell me about the disadvantages.
Selenium RC injects Javascript into the page to drive the interactions. Webdriver interacts directly with the browser. Injecting additional Javascript has disadvantages, with the Selenium HQ site stating it rather well.
While Selenium was a tremendous tool, it wasn’t without its drawbacks.
Because of its Javascript based automation engine and the security
limitations browsers apply to Javascript, different things became
impossible to do. To make things “worst”, webapps became more and more
powerful over time, using all sorts of special features new browsers
provide and making this restrictions more and more painful.
http://seleniumhq.org/docs/01_introducing_selenium.html#selenium-history
Another way to think about it is that testing a page that has had more JS added, you're not really testing the original page; you're testing a modified page.
What #OCary said.
However, the new and more powerful WebDriver has some limitations, too. Because it is a work-in-progress, it's behaviour between different versions changes slightly from time to time. Also, not nearly all intended features have been implemented yet, it will take some more time to have it stable, bug-free and fully developed. For example: the SafariDriver has just landed, the window controls are missed, you can't download files in a convenient way etc.
But a healthy development on WebDriver is better than today's non-existant development on Selenium 1 (It just won't get any better.), right?
From my experience Selenium RC is the most stable and robust web testing framework I have used. I recently started evaluating WebDriver (aka Selenium 2) for the reason that everybody says it is the future of Selenium. So far I am not impressed. Simple things (like clicking a button) do not work consistently across different browsers and require different workarounds.
I realize that there are limitations in what you can do with JavaScript, but I would not want to sacrifice the stability of my tests to get over those limitations.

Selenium Issues

I have been using Selenium a lot lately (testing an ExtJs app) and while in many ways it is wonderful, there are three things that cause me a lot of grief:
Inability to directly click on elements other than buttons. This has led me to write a bunch of Robot code to move the mouse around. That works but is a bit fragile, plus if you touch your mouse while a test is running, you are screwed. I tried the Selenium forums to see if there was a better way, and got nowhere. I think (but am not sure) that this is a fundamental limitation of Selenium's JS injection technique.
Inability in many cases to control what the 'id' attribute get sets to. This happens inside ExtJs and some elements let you set it, some don't, and some do but the attribute ends up where you don't expect it. You end up having to use XPath in some cases. Using XPath with ExtJs is kind of horrible as ExtJs creates massive levels of nested DIV's. You can also sometimes use CSS locators (which are also inconsistently controllable in ExtJs). (BTW, this is obviously not a Selenium problem per se).
The time that Selenium takes to fire up FF is too long... way longer than a normal human FF startup, about 2 seconds per test, which translates into tests that last several minutes, way too long.
I briefly looked at Watij, BadBoy and a couple of other web functional testing apps but none of them looked anywhere near as good as Selenium. (The way Selenium tests can be written in Java and run through jUnit is really, really sweet). There are also a few commercial alternatives but they are beyond my budget and there is no assurance that they would work any better anyway.
Any thoughts or suggestions appreciated.
About 3:
Selenium copies at startup the firefox profile to a temporary folder. If you don't specify a custom profile, Selenium propably uses the default profile which propably is bloated with addons you don't need for the test. Startup Firefox with '-p' and create a new profile for Selenium and copy it to a location you can point selenium to. This should speed up the test a bit.
Update:
Firefox Profile location / Windows: %APPDATA%\Mozilla\Firefox\Profiles
My thoughts:
There are some cases that click isn't enough, but you certainly shouldn't be limited to buttons. You might want to experiment further with your locators.
Why do you need to set the id attribute of elements? I have experience with testing ExtJS applications, and the problem is usually locating elements that have dynamically set ids. In my opinion this is an issue with ExtJS and not Selenium. Using smart XPath techniques using contains, starts-with, and substring can make your locators much more reliable. CSS locators are also often helpful as you mentioned.
As amarsuperstar says, you don't need to start Firefox before every test. If you do, you might want to consider using the browserSessionReuse command to speed up launching the browser. Alternatively you can use Selenium Grid to run tests in parallel.
Finally, it's well worth looking into the WebDriver API that will be in the soon to be released alpha of Selenium 2. In my experience Firefox launch times are reduced, and commands such as click are much improved.
I am not sure about the first two points, but as for the third, I don't think you need to start the browser for every test. You can use the Seleium server (a jar in the selenium directory somewhere) then point your tests to that e.g. localhost:6554 and that will only open the browser once.
With that you can have the steps in your script to start server -> run all test -> terminate server and you will only have one browser session across your tests.
My experiences (hopefully useful ;)
I've never had this problem, even with ExtJS. I have not used it with ExtJS 3.x, though. Is it possible that you are experiencing some thing as a result of your environment rather than Selenium?
UPDATE: As Dave Hunt reminded me, sometimes I've had to use mousedown/mouseup actions in lieu of "click"
I've found many clever ways to navigate using CSS locators (selenium supports most of CSS 3). In addition, you can use xpath like xpath=id('myid')//div['#class='foo'] (the ID part is crucial).
I've also never experienced this. Perhaps you can give some details about your environment?
Thanks for all the answers guys, I really appreciate it. I spent all day yesterday on this stuff and I wanted to add a couple of observations:
The way ExtJS lays stuff out can really make it hard to locate elements. For example, quite often the 'id' that you specified appears on an element that is 2-3-4 items in the DOM above the one you really want. The actual behaviour seems to vary greatly depending on the type of element. I have half a mind to write all this up for the benefit of future Se-ExtJs testers, as it all seems very trial-and-error and tedious. But ultimately it seems like it can be made to work nicely. And, of course, this is in no way a reflection on Se. Whether it reflects poorly on ExtJs, I'm not really sure, but it is amazing how many DIV tags even fairly simple projects create.
This is probably a 'well OBVIOUSLY' but to anyone else doing this, I'd recommend getting comfy with XPath. It seems a bit obtuse at first but after a few hours, as noted above, you can find almost anything with it, and almost always in ways that are not overly brittle.
Happy Holidays!
Selenium is one of the backends to the TestPlan testing framework and it can address a few of these issues for you.
We don't seem to have any problems here. Our front-end uses many different locator syntaxes to locate any elements on the screen. Though if your page is complicated and Selenium truly can't do it then ours won't help you either.
We base everything on XPath, so after a while you just get used to it. There are all sorts of shortcut syntax that you can use in XPath that may help. In TestPlan scripts however you can also use variable expansion in XPaths which makes them much easier to maintain.
TestPlan caches browser sessions when possible and not otherwise requested. This helps the speed a little bit, but only so much since normally you want a fresh session for each test anyway.
TestPlan