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

Telephone field #64

Merged
merged 3 commits into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions documentation/chapters/page-object-functional.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ public class Headline extends PageObject {

- `<tr/>`

## TelephoneField
**Extends:** GenericTextField

**HTML Tags:**

- `<input type="tel"/>`

## TextArea
**Extends:** TextField

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package info.novatec.testit.webtester.pageobjects;

import info.novatec.testit.webtester.api.annotations.Mapping;

@Mapping(tag = "input", attribute = "type", values = {"tel"})
public class TelephoneField extends GenericTextField<TelephoneField>{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package info.novatec.testit.webtester.pageobjects;

import info.novatec.testit.webtester.AbstractPageObjectTest;
import info.novatec.testit.webtester.api.exceptions.WrongElementClassException;
import org.junit.Test;
import org.mockito.InjectMocks;

public class TelephoneFieldTest extends AbstractPageObjectTest{

@InjectMocks
TelephoneField cut;

@Test
public final void testCorrectnessOfClassForWebElement_inputTag_telephoneFieldType() {
stubWebElementTagAndType("input", "tel");
cut.validate(webElement);
}

@Test (expected = WrongElementClassException.class)
public final void testCorrectnessOfClassForWebElement_nonInputTag() {
stubWebElementTagAndType("other", null);
cut.validate(webElement);
}

@Test (expected = WrongElementClassException.class)
public final void testCorrectnessOfClassForWebElement_nonTelephoneFieldType() {
stubWebElementTagAndType("input", "other");
cut.validate(webElement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.File;

import info.novatec.testit.webtester.pageobjects.PageObject;
import org.junit.Before;
import org.junit.BeforeClass;

Expand Down Expand Up @@ -54,6 +55,10 @@ protected String getHTMLFilePath() {

// UTILITY

protected void assertPageObjectCanBeInitialized(PageObject object) {
assertThat(object.isPresent(), is( true));
}

protected static Browser getBrowser() {
return browser;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package integration.pageobjects;

import info.novatec.testit.webtester.api.annotations.IdentifyUsing;
import info.novatec.testit.webtester.api.exceptions.WrongElementClassException;
import info.novatec.testit.webtester.pageobjects.PageObject;
import info.novatec.testit.webtester.pageobjects.TelephoneField;
import integration.AbstractWebTesterIntegrationTest;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;

import javax.annotation.PostConstruct;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;


public class TelephoneFieldIntegrationTest extends AbstractWebTesterIntegrationTest{
TelephoneFieldTestPage page;

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

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

/* getting text */

@Test
public final void testThatGettingTextWorksWithParentImplementation() {
assertThat(page.withValue.getText(), is("0123456789"));
}

/* appending text */

@Test
public final void testThatAppendingOfTextWorksWithParentImplementation() {
TelephoneField element = page.withValue.appendText("000");
assertThat(element.getText(), is("0123456789000"));
}

/* setting text */

@Test
public final void testThatSettingOfTextWorksWithParentImplementation() {
TelephoneField element = page.empty.setText("0123456789");
assertThat(element.getText(), is("0123456789"));
}

@Test
public final void testThatSettingTextWithValueWorksWithParentImplementation() {
TelephoneField element = page.withValue.setText("still 0123456789");
assertThat(element.getText(), is("still 0123456789"));
}


/* clearing text */

@Test
public final void testThatClearingOfTextWorksWithParentImplementation() {
TelephoneField element = page.withValue.clearText();
assertThat(element.getText(), is(""));
}

/* validation of mapping */

@Test
public final void testValidationOfMapping_telephoneField() {
assertPageObjectCanBeInitialized(page.empty);
}

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

/* utilities */

public static class TelephoneFieldTestPage extends PageObject {
@IdentifyUsing("empty")
TelephoneField empty;

@IdentifyUsing("withValue")
TelephoneField withValue;

@IdentifyUsing("notATelephoneField")
TelephoneField notATelephoneField;

@PostConstruct
void checkStartingConditions() {
assertThat(empty.isVisible(), is(true));
assertThat(withValue.isVisible(), is(true));

assertThat(empty.getText(), is(StringUtils.EMPTY));
assertThat(withValue.getText(), is("0123456789"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<body>

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

<hr>
<br><br>

<table>
<tbody>
<tr>
<td>An telephone email field</td>
<td><input type="tel" id="empty" value=""></td>
</tr>
<tr>
<td>A telephone field with a preset value</td>
<td><input type="tel" id="withValue" value="0123456789"></td>
</tr>
<tr>
<td>A non telephone field</td>
<td><span id="notATelephoneField">This is not a telephone field</span></td>
</tr>
</tbody>
</table>

<br><br>
<hr>

</body>
</html>