LoginSignup
26
26

More than 5 years have passed since last update.

[Java][test] Java Webテストツール文法まとめ

Last updated at Posted at 2015-09-10

概要

http://java-source.net/open-source/web-testing-tools で紹介されているテストツールを使用したテストの書き方をまとめてみました。

HtmlUnit

順当な感じです。

@Test
public void homePage() throws Exception {
    final WebClient webClient = new WebClient();
    final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
    Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());

    final String pageAsXml = page.asXml();
    Assert.assertTrue(pageAsXml.contains("<body class=\"composite\">"));

    final String pageAsText = page.asText();
    Assert.assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols"));

    webClient.closeAllWindows();
}

MaxQ

プロキシ型なので割愛。

jWebUnit

DSLっぽくていい感じ。

import org.junit.*;

import static net.sourceforge.jwebunit.junit.JWebUnit.*;

public class ExampleWebTestCase {

    @Before
    public void prepare() {
        setBaseUrl("http://localhost:8080/test");
    }

    @Test
    public void testLogin() {
        beginAt("/home");
        clickLink("login");
        assertTitleEquals("Login");
        setTextField("username", "test");
        setTextField("password", "test123");
        submit();
        assertTitleEquals("Welcome, test!");
    }
}

HttpUnit

順当な感じ。

    WebConversation wc = new WebConversation();
    WebResponse   resp = wc.getResponse( "http://www.httpunit.org/doc/cookbook.html" ); // read this page
    WebLink       link = resp.getLinkWith( "response" );                                // find the link
    link.click();                                                                       // follow it
    WebResponse   jdoc = wc.getCurrentPage();                                           // retrieve the referenced page

Canoo WebTest

XMLなんだ。。。ちょっとつらそう。

<project default="test">
 <target name="test">

  <webtest 
       name="check that WebTest is Google's top 'WebTest' result">
    <invoke url="http://www.google.com/ncr" 
            description="Go to Google (in English)"/>
    <verifyTitle text="Google" />
    <setInputField name="q" value="WebTest" />
    <clickButton label="I'm Feeling Lucky" />
    <verifyTitle text="Canoo WebTest" />
  </webtest>

 </target>
</project>

JMeter

負荷テストでした。

LoadSim

負荷テストでした。

Lakta

リンク切れ。

StoryTestMQ

Seleniumを使用。

Slimdog

リンク切れ。

Imprimatur

リンク切れ。

slim

リンク切れ。

Selenium

WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("Selenium");
driver.

Watij

よさげ。

WebSpec spec = new WebSpec().mozilla();
spec.open("http://www.google.com");
spec.find.input().with.name("q").set.value("Watij");
spec.find.input().with.type("button").with.value("Google Search").click();
//check results
spec.find.a().with.href("http://watij.com/").shouldExist();
26
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
26