Selenium WebDriver and Play

big-logo
I have advocated tests using Selenium WebDriver in the past many times. Will it become a de facto standard now that frameworks like Play make it very easy ?

It is not even evident below that Selenium WebDriver is being used. It is HTMLUNIT that is imported statically.

A test server is started, a test application is setup and a browser is simulated, all in a few lines of code. Very economical.


import static org.fest.assertions.Assertions.assertThat;
import static play.test.Helpers.*;

import org.junit.Test;

import controllers.routes;
import play.Logger;
import play.libs.F.Callback;
import play.test.TestBrowser;
import static helpers.TestSetup.*;

public class ProposalSubmissionTest {

	@Test
	public void proposalTest(){
		running(testServer(3333,fakeApplication(testDbSettings())),HTMLUNIT, new Callback<TestBrowser>(){

			@Override
			public void invoke(TestBrowser browser) throws Throwable {
				browser.goTo("http://localhost:3333" + routes.MainController.newProposal().url());
				assertThat(browser.title()).isEqualTo("New Proposal");
				Logger.debug(browser.title());
			}
			
		});
	}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: