0

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

请帮忙。

4

0 回答 0