Sunday, November 4, 2012

Selenium 2.0


Selenium 2.0
       The next major version of Selenium is going to change a lot of things on the Selenium internals
       Selenium 1.0 + WebDriver = Selenium 2.0
       Currently, Selenium 2.0 is still in development
       It was released in 2011
History
 
       The biggest change in Selenium recently has been the inclusion of the WebDriver API
       Driving a browser natively as a user
Some cases connect webdriver
       HtmlUnit Driver
             WebDriver driver = new HtmlUnitDriver();
       Firefox Driver
            WebDriver driver = new FirefoxDriver();
       Internet Explorer Driver
                       WebDriver driver = new ChromeDriver();
       Chrome Driver
            WebDriver driver = new ChromeDriver();
       Opera Driver
       iPhone Driver : Mac iOS Driver
       Android Driver : Android Driver

WebDriver Interface
1.       Load the page
                Webdriver driver = new FireFoxDriver();
        driver.get("http://www.google.com");
2.    Navigation the page
                  driver.navigate().to("http://www.example.com");
                  driver.navigate().forward();
                  driver.navigate().back();
3.    Assertions on the page title
       Assert.assertEquals(String, webdriver.getTitle());
Killing the webdriver instances
                  webdriver.quit();
5.       Page interactions
                webElement.Click()
                webElement.SendKeys()
                webEkement.submit()
                Action class -> Mouse Events /Drag and Drop
Using the finElement method
 -  By ID
-  By Class Name
-  By Tag Name
-  By Name
-  By Link Text
-  By Partial Link Text
-  By CSS
-  By XPATH
-  By JavaScript
Example

List WebElement
                List <WebElement> webElements = webdriver.findElements                                                                                         (By.xpath(…));
Assertion on the number of items
                 Assert.AssertEquals(5, Webelements.size());
When you are using WebDriver for test automation a test case really boils down to:
     1. Find an element
     2. Perform an action
     3. Confirm the expected result

4 comments:

  1. Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms(download newest version)
    => Download version 2.25.0 in link http://seleniumhq.org/download/

    ReplyDelete
  2. Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"xpath","selector":"//html/body/div[2]/div/div[3]/form/div/div/input"}
    Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
    System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24'

    Anwer: driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    ReplyDelete
  3. Selenium RC:
    Could not contact Selenium Server; have you started it on 'localhost:4444' ?
    [testng] Read more at http://seleniumhq.org/projects/remote-control/not-started.html
    [testng] Connection refused: connect

    Answer:
    You run server such as:
    cmd->d:
    cd D:\Testing\Selenium\hoa-selenium\selenium_server
    D:\Testing\Selenium\hoa-selenium\selenium_server>java -jar selenium-server-standalone-2.21.0.jar

    ReplyDelete
  4. Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function

    Anwer: Download selenium-server-standalone-version.jar

    ReplyDelete