Comparison of selenium and Webdriver

Source: Internet
Author: User
Tags comparison log mail

Tracing traceability, webdriver and Selenium are two independent projects, and the implementation mechanism is different. Why would the Selenium team merge the two in Selenium 2? What advantage does Webdriver have over Selenium? How do we choose to use Selenium or Webdriver? Don't worry, you'll find the answer in this article, and you'll learn a little bit about the basics and how to use Webdriver.

For the convenience of presentation, in this article, we call Selenium 2 Webdirver,selenium as Selenium 1.x (because selenium1.x usually refers to Selenium RC, so Selenium also refers to Selenium RC )。

Webdriver is ...?

Selenium 2, also known as Webdriver, its main new feature is the integration of the Selenium 1.0 and Webdriver (Webdriver was once a competitor for Selenium). That is to say, Selenium 2 is a combination of two projects Selenium and Webdriver, Selenium 2 compliant Selenium, which supports both the Selenium API and the Webdriver API.

Why would the Selenium team merge two projects? We generally think that part of the reason is that Webdriver solves the drawbacks of Selenium (for example, the ability to bypass the JS sandbox), partly because Selenium solves problems with Webdriver (for example, supporting a wider range of browsers and programming languages), Whatever the real reason is. The merging of two projects provides users with an excellent automated testing framework.

Now let's look at the specific differences between the two tools. Before we begin, we will first look at the test works that are constructed with Selenium and Webdriver, and then explain the similarities and differences of Webdriver and Selenium on this basis.

Description: Because now Webdriver is still in the process of improvement and optimization, so the following examples and instructions are based on the version selenium-2.28.0.

Build a Selenium test project

The Selenium API supports more programming languages, and here we take Java as an example.

Figure 1. Selenium Test Project

Listing 1. Script using the Selenium API-login SmartCloud iNotes

Package demo;
Import Com.thoughtworks.selenium.DefaultSelenium;
    
Import Com.thoughtworks.selenium.Selenium; public class Seleniumdemo {public static void main (string[] args) throws Interruptedexception {//Create a Sele Nium instance Selenium Selenium = new Defaultselenium ("localhost", 4444, \ "*firefox", "https://apps.na.collabserv.com/"
    
        );
        Start Selenium session selenium.start ();
        Open test page Selenium.open ("https://apps.lotuslive.com/");
Enter username, password selenium.type ("//input[@id = ' username ']", \ "autouser01@e3yunmail.mail.lotuslive.com");
        Selenium.type ("//input[@id = ' password ']", "Test");
        Login Selenium.click ("//input[@id = ' submit_form ']");
Wait until the page appears Mail link int count = 60; while (Count > 0) {if (Selenium.iselementpresent ("//a[contains (Text (), ' Mail ')]") {break;}
 else{Thread.Sleep (1000);
            count--; }//Log Out Selenium.click ("A[contains (Text (), ' Log out ')];
    After testing, terminate selenium session selenium.stop (); }
}

Build a Webdriver test project

The Webdriver API can be accessed through Python, Ruby, Java, and C #, enabling developers to create tests using their preferred programming language. Here we take Java as an example. First you need to prepare your Eclipse environment and download the Selenium 2 Jar package on the official website of selenium.

Figure 2. Webdriver Test Project

Listing 2. Script using the Webdriver API-login Smartcoud iNotes

Package demo;
Import Org.openqa.selenium.By;
Import Org.openqa.selenium.WebDriver;
Import org.openqa.selenium.WebElement;
Import Org.openqa.selenium.firefox.FirefoxDriver;
Import org.openqa.selenium.support.ui.ExpectedCondition;
    
Import org.openqa.selenium.support.ui.WebDriverWait; public class Webdriverdemo {public static void main (string[] args) {//Create a Firefox driver instance Webdriver Drive
        R = new Firefoxdriver ();
Open Test URL driver.get ("https://apps.na.collabserv.com/");
        Defines the username and password text box webelement username=driver.findelement (by.id ("username"));
        Webelement password=driver.findelement (by.id ("password"));
        Enter username and password Username.sendkeys ("autouser01@e3yunmail.mail.lotuslive.com");
        Password.sendkeys ("test");
        Click Login Login Webelement login=driver.findelement (by.id ("Submit_form"));
        Login.click (); Set the page to wait until the Mail link appears (new webdriverwait (driver). Until (new expectedcondition<webelement> () {public WeBelement apply (Webdriver dr) {return dr.findelement (By.linktext ("Mail"));
        }
        });
        Log out of the Webelement logout=driver.findelement (By.linktext ("Log out"));
        Logout.click ();
    Close browser driver.quit (); }
}

Selenium vs Webdriver

From the above two test projects built with Selenium and Webdriver, the Webdriver project can be used directly after construction, which is quite different from the Selenium. Because Selenium also needs to install and start Selenium Server to run the test program.

In addition, we can see that Webdriver is based on object-oriented API, it is more from the user point of view. Conversely, Selenium provides a dictionary based API, and users can easily see the supported methods. There is no doubt that the API provided by Webdriver is more concise and more user-friendly. But from another point of view, is that users can not be very intuitive to see Webdriver provided which APIs, may need to be provided through the official website JavaDoc (Source: http://selenium.googlecode.com/svn/trunk/docs/ api/java/index.html) to find some ways to help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.