0

HtmlUnitDriver is not working properly. Below are the sample code. What am i doing wrong?

import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.gargoylesoftware.htmlunit.BrowserVersion;

public class HtmlUnitDriver_Example 
{
    public static HtmlUnitDriver driver = null;

    @BeforeClass
    public void setUp() 
    {
        driver = new HtmlUnitDriver(BrowserVersion.INTERNET_EXPLORER_11);
        driver.setJavascriptEnabled(true);
    }

    @Test
    public void Test_01()
    {
        System.out.println("Trying to execute Test_01");
        driver.get("https://www.google.co.in");
        System.out.println(driver.getPageSource());
        System.out.println(driver.getTitle());
    }

    @AfterClass
    public void tearDown() 
    {
        driver.quit();
    }
}

Below two lines are not returning anything meaningful on console.

System.out.println(driver.getPageSource());
System.out.println(driver.getTitle());

Instead, I got the following output;

[TestNG] Running:
  C:\Users\acer\AppData\Local\Temp\testng-eclipse--592945208\testng-customsuite.xml

Trying to execute Test_01
<?xml version="1.0" encoding="UTF-8"?>
<html>
  <head/>
  <body/>
</html>


PASSED: Test_01

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Please help.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
asu
  • 97
  • 10
  • You are using an old version, please use latest one, which prints the page source plus `Google` as the title – Ahmed Ashour Nov 06 '15 at 15:12
  • version of what? I am using Selenium 2.48.2. If TestNG then yes, I am using an older one, but getting the same result if not using TestNG at all. – asu Nov 07 '15 at 12:26
  • Yes, with Selenium 2.48.2 your test works with me. The only change is that `setUp()` and `tearDown()` must be static – Ahmed Ashour Nov 07 '15 at 19:26
  • @AhmedAshour..I think setup() and teardown() must be static only in Junit. It can be non static in TestNG. Please Correct me if I am wrong. – StrikerVillain Nov 09 '15 at 12:36
  • @asu... I am getting the output as expected. – StrikerVillain Nov 09 '15 at 12:42
  • @Striker, yes. It runs fine on other systems but mine. Trying to find out the reason. Thanks. – asu Nov 09 '15 at 13:03

0 Answers0