Selenium 1.0 vs Selenium 2.0 (Selenium Web-driver)

試著忘記壹切 提交于 2019-12-01 00:28:20
Selenium is browser automation tool, for more information select this link.
We already have Selenium1.0, why Selenium2.0?

Selenium1.0 can't tackle following items.
1. Native keyboard and mouse events.
2. Same origin policy XSS/HTPP(S)
3. Pop-ups, dialogs (Basic authentication, Self signed certificates and File upload/download)

Selenium2.0 has cleaner API, webdriver and webelements object, better abstraction.
//Web driver object
browser = webdriver.firefox()
//Web element object, to refer any object on the browser
search_box_google = browser.find_element_name('q')
Support of mobile devices- Android, iOS (Open web testing)
node.JS is server side JavaScript new programming language supported.
I have not seen  Java Docs for Opera and Safari browsers.




Support for different types of mobile testing
1. Emulator.
2. Device connected to workstation.
3. Real device on real location on real network

Improved architecture.
Removing road blocks, hacks and workarounds
Scales up/down.
Selenium2 = Webdriver + Selenium1.0 (merging two different projects)



Lets understand the reason behind merging these two projects.

Selenium 1.0 - You can program in any language, but the prerequisite is that it should support HTTP library.  It initially started as bucket of JavaScript, later Selenium RC(Remote Control) was introduced. RC is a headless Java serer that acts as a proxy server to send commands to to the Selenium Core (JavaScript program that is running in the browser, set of functions). RC receives commands from the test program, interprets them, report back the results of those tests to the test program.  RC consist of Selenium core, that is inject into the browser using client library API when the test program opens the browser. Selenium core interprets the commands coming from the test program and execute selenese commands using browsers built-in JavaScript engine.

Selenium is the first open source browser based testing framework that quickly added support for new browsers as it is written in JavaScript.

Like any large project, Selenium is not perfect. As it is entirely written in JavaScript, which causes significant weakness. Every browser impose very strict security rules on the JavaScript being executed to protect the users from malicious scripts. This make testing harder for some scenarios. For example IE JavaScript security model don't allow to change the value of the INPUT file element for uploading the file and navigating between different domains ( same origin policy) .
As it is a mature product, Selenium APIs has grown over time and it becomes harder to understand how best to use it.

Webdriver project was created by Simon Stewart, it is a clean and fast framework for browser testing automation. Webdriver take different approach for the problems faced by selenium (discussed above). Rather than being a JavaScript application used in the browser, it uses whichever mechanism is most appropriate to control the browser. IE - C++ mainly using automation APIs, Firefox - JavaScript in a XPCOM component (Add-in) ,Chrome - ???.
By changing the mechanism used to control the browser we can overcome the JavaScript security model. When these techniques are not sufficient, Webdiver can use facilities provided by operating System, especially when user want to simulate inputs from the Keyboard and mouse. By using these techniques we are trying to simulate how a real user interact with the browser.
Webdriver had Object Base API when compared with the Selenium which as Directory based approach.
Webdriver JAVA API looks like this.
// Create an instance of WebDriver backed by Firefox
WebDriver driver = new FirefoxDriver();

// Now go to the Google home page
driver.get("http://www.google.com");

// Find the search box, search for something
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("selenium");

// And now display the title of the page
System.out.println("Title: " + driver.getTitle());
When these two frameworks are compared side by side, weakness of one framework is addressed by other.
Webdriver support for multiple browsers require lot of effort from the framework developers, where as selenium can be easily extended. Selenium always require real browser, but it can make use of Webdriver HTML unit driver which is very fast and light weight browser that execute in the system memory. Selenium solve most of the common situations in an automation testing, but Webdriver ability to support out side the JavaScript sandbox provides more interesting possibilities. Webdriver don't support parallel testing, where as Selenium has answer by using Selenium GRID (new GRID 2.0 require selenium server). Although this would not solve the limitations of existing Selenium JavaScript, but it would become easier to test broad range of browsers.

Webdriver APIs are used for driving the browsers as per the user requirement, every browser has most natural language "Best Fit" for driving it, so that each developer can develop the driver independently.
But there is a problem, a fix made to one driver don't guarantee that the same fix will resolve the issue in other drivers. Every programmer is good in his own language, Java programmer many not be efficient in writing C++ programs, this create lot of redundant work across the drivers and huge testing activity.
Now the team came up with the concept of Atoms, they have decided to merge the common code across the drivers so that maintenance and development is easy. What will be the common code across all the drivers? Querying the state of browser to find an element and getting attribute values from the page DOM is the major effort across the drivers, the best common language across all the browsers for accessing DOM is by using JavaScript and this is what Selenium Core consist of. Instead of loading the single large JavaScript file into the browser and creating burden on the browser engine. They have decided to break the code into chunks(i.e Atoms), compress the JavaScript with other tools and load it on demand. These atoms are common across all the drivers.
IE browser use C++ as best fit language, how do they pass atoms(JavaScript) to it? I think by placing it in header files.

Following are the drivers available in Selenium2.0 currently
AndroidDriverChromeDriverEventFiringWebDriverFirefoxDriverHtmlUnitDriverInternetExplorerDriverIPhoneDriverIPhoneSimulatorDriverRemoteWebDriver

Name of driver Available on which OS? Class to instantiate
HtmlUnit Driver All org.openqa.selenium.htmlunit.HtmlUnitDriver
Firefox Driver All org.openqa.selenium.firefox.FirefoxDriver
Internet Explorer Driver Windows org.openqa.selenium.ie.InternetExplorerDriver
Chrome Driver All org.openqa.selenium.chrome.ChromeDriver
HTMLUnit driver is a pure Java driver that run in memory without displaying the browser on the screen. It use Rihno as JavaScript engine.

Selenium2 five minutes starting guide
Selenium2 documentation
Selenium2 webdriver new kid

Enjoy using Selenium 2.0 clean API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!