Java Tests

Since version 2.0 Galen introduced an improved Java API allowing you to perform layout testing in you Java Selenium Tests.

Maven dependency

If you are using Maven you can add a following dependency in your pom.xml

<dependencies> ... <dependency> <groupId>com.galenframework</groupId> <artifactId>galen-java-support</artifactId> <version>2.0.3</version> </dependency> ... </dependencies>

Simplest usage

public class WelcomePageTest extends GalenTestNgTestBase { @Override public WebDriver createDriver(Object[] args) { return new FirefoxDriver(); } @Test public void welcomePage_shouldLookGood_onDesktopDevice() { load("http://example.com", 1024, 768); checkLayout("/specs/welcomePage.spec", asList("mobile")); } }

HTML reports

It is also possible to save your layout tests into a separate HTML report in a same way it is generated during regular Galen tests.

// .... // Executing layout check and obtaining the layout report LayoutReport layoutReport = Galen.checkLayout(driver, "specs/loginPage.gspec", Arrays.asList("mobile"), null, null, null); // Creating a list of tests List<GalenTestInfo> tests = new LinkedList<GalenTestInfo>(); // Creating an object that will contain the information about the test GalenTestInfo test = GalenTestInfo.fromString("Login page on mobile device test"); // Adding layout report to the test report test.getReport().layout(layoutReport, "check layout on mobile device"); tests.add(test); // Exporting all test reports to html new HtmlReportBuilder().build(tests, "target/galen-html-reports");

Automatic reports generation for Maven project

Galen Framework comes out of the box with reports storage and HTML reports generator. If you inherit all your test class from com.galenframework.testng.GalenTestNgTestBase then all your test reports will be automatically stored in com.galenframework.support.GalenReportsContainer class. In the end of the test suite you can obtain all the test reports and save them in HTML format. Actually there is already a TestNG listener for that: com.galenframework.testng.GalenTestNgReportsListener. Just add this listener in your pom file like in the example below:

<!- ... --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <properties> <property> <name>usedefaultlisteners</name> <value>false</value> </property> <property> <name>listener</name> <value>com.galenframework.testng.GalenTestNgReportsListener</value> </property> </properties> </configuration> </plugin> <!- ... -->

Parallel Execution

When using Maven Surefire, you can run the tests in parallel. Either include it in your pom or via parameters:

mvn verify -DforkCount=2 -DreuseForks=true

Don’t use parallel excution via method-level!

Comments

We have moved all the discussions to Google Groups. From this moment, if you have problems with your test code or some issues with installation, please ask your questions in https://groups.google.com/forum/#!forum/galen-framework.