HtmlUnitDriver不起作用

时间:2015-11-06 14:05:38

标签: java selenium selenium-webdriver htmlunit-driver

HtmlUnitDriver无法正常运行。以下是示例代码。我究竟做错了什么?

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();
    }
}

以下两行没有在控制台上返回任何有意义的内容。

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

相反,我得到了以下输出;

[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
===============================================

请帮忙。

0 个答案:

没有答案