Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
Added FormIntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopaul committed Jan 2, 2017
1 parent 2b6354b commit 83566b2
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions documentation/chapters/event-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The `webtester-core` module provides events for all it's actions:

- `ClickedEvent`
- `DoubleClickedEvent`
- `FormSubmittedEvent`
- `SelectedByIndexEvent`
- `SelectedByTextEvent`
- `SelectedByValueEvent`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package integration.pageobjects;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

import org.junit.Before;
import org.junit.Test;

import integration.AbstractWebTesterIntegrationTest;

import info.novatec.testit.webtester.api.annotations.IdentifyUsing;
import info.novatec.testit.webtester.api.exceptions.WrongElementClassException;
import info.novatec.testit.webtester.pageobjects.Form;
import info.novatec.testit.webtester.pageobjects.PageObject;



public class FormIntegrationTest extends AbstractWebTesterIntegrationTest{

FormTestPage page;

@Before
public void initPage() {
page = getBrowser().create(FormTestPage.class);
}

@Override
protected String getHTMLFilePath() {
return "html/pageobjects/form.html";
}

/* submit */

@Test
public final void testThatSubmitDelegatesToTargetPage() {
page.form.submit();
assertThat(getBrowser().getPageTitle().equals("Target Page"), is(true));
}

@Test(expected = WrongElementClassException.class)
public final void testThatSubmitFailsIfNoFormIsGiven() {
page.notAForm.submit();
}

/* validation of mapping */

@Test
public final void testValidationOfMapping_form() {
assertPageObjectCanBeInitialized(page.form);
}

@Test(expected = WrongElementClassException.class)
public final void testValidationOfMapping_noForm() {
assertPageObjectCanBeInitialized(page.notAForm);
}

/* utilities */

public static class FormTestPage extends PageObject {

@IdentifyUsing("form")
Form form;

@IdentifyUsing("notAForm")
Form notAForm;

}
}
36 changes: 36 additions & 0 deletions webtester-core/src/test/resources/html/pageobjects/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../_style.css">
</head>
<body>

<h1>Form Test Page</h1>
<h3>This page contains elements for testing the functionality of the Form page fragment class.</h3>

<hr>
<br><br>

<table>
<tbody>
<tr>
<td>A Form</td>
<td>
<form id="form" action="_targetPage.html">
<input type="text">
<input type="text">
</form>
</td>
</tr>
<tr>
<td>Not a Form</td>
<td><span id="notAForm">This is not a DIV</span></td>
</tr>
</tbody>
</table>

<br><br>
<hr>

</body>
</html>

0 comments on commit 83566b2

Please sign in to comment.