|
| 1 | +package com.baeldung.convListVal; |
| 2 | + |
| 3 | +import static org.jboss.arquillian.graphene.Graphene.guardHttp; |
| 4 | + |
| 5 | +import java.io.File; |
| 6 | +import java.net.URL; |
| 7 | + |
| 8 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 9 | +import org.jboss.arquillian.container.test.api.RunAsClient; |
| 10 | +import org.jboss.arquillian.drone.api.annotation.Drone; |
| 11 | +import org.jboss.arquillian.junit.Arquillian; |
| 12 | +import org.jboss.arquillian.test.api.ArquillianResource; |
| 13 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 14 | +import org.jboss.shrinkwrap.api.asset.EmptyAsset; |
| 15 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 16 | +import org.junit.Assert; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.runner.RunWith; |
| 19 | +import org.openqa.selenium.By; |
| 20 | +import org.openqa.selenium.WebDriver; |
| 21 | +import org.openqa.selenium.WebElement; |
| 22 | +import org.openqa.selenium.support.FindBy; |
| 23 | + |
| 24 | +@RunWith(Arquillian.class) |
| 25 | +public class ConvListValTest { |
| 26 | + |
| 27 | + @ArquillianResource |
| 28 | + private URL deploymentUrl; |
| 29 | + |
| 30 | + private static final String WEBAPP_SRC = "src/main/webapp"; |
| 31 | + |
| 32 | + @Deployment(testable = false) |
| 33 | + public static WebArchive createDeployment() { |
| 34 | + return ( ShrinkWrap.create( |
| 35 | + WebArchive.class, "jee7.war"). |
| 36 | + addClasses(ConvListVal.class, MyListener.class)). |
| 37 | + addAsWebResource(new File(WEBAPP_SRC, "ConvListVal.xhtml")). |
| 38 | + addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); |
| 39 | + } |
| 40 | + |
| 41 | + @Drone |
| 42 | + WebDriver browser; |
| 43 | + |
| 44 | + @ArquillianResource |
| 45 | + URL contextPath; |
| 46 | + |
| 47 | + @FindBy(id="myForm:age") |
| 48 | + private WebElement ageInput; |
| 49 | + |
| 50 | + @FindBy(id="myForm:average") |
| 51 | + private WebElement averageInput; |
| 52 | + |
| 53 | + @FindBy(id="myForm:send") |
| 54 | + private WebElement sendButton; |
| 55 | + |
| 56 | + @Test |
| 57 | + @RunAsClient |
| 58 | + public void givenAge_whenAgeInvalid_thenErrorMessage() throws Exception { |
| 59 | + browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); |
| 60 | + ageInput.sendKeys("stringage"); |
| 61 | + guardHttp(sendButton).click(); |
| 62 | + Assert.assertTrue("Show Age error message", browser.findElements(By.id("myForm:ageError")).size() > 0); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + @RunAsClient |
| 67 | + public void givenAverage_whenAverageInvalid_thenErrorMessage() throws Exception { |
| 68 | + browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); |
| 69 | + averageInput.sendKeys("stringaverage"); |
| 70 | + guardHttp(sendButton).click(); |
| 71 | + Assert.assertTrue("Show Average error message", browser.findElements(By.id("myForm:averageError")).size() > 0); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @RunAsClient |
| 76 | + public void givenDate_whenDateInvalid_thenErrorMessage() throws Exception { |
| 77 | + browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); |
| 78 | + averageInput.sendKeys("123"); |
| 79 | + guardHttp(sendButton).click(); |
| 80 | + Assert.assertTrue("Show Date error message", browser.findElements(By.id("myForm:myDateError")).size() > 0); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + @RunAsClient |
| 85 | + public void givenSurname_whenSurnameMinLenghtInvalid_thenErrorMessage() throws Exception { |
| 86 | + browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); |
| 87 | + averageInput.sendKeys("aaa"); |
| 88 | + guardHttp(sendButton).click(); |
| 89 | + Assert.assertTrue("Show Surname error message", browser.findElements(By.id("myForm:surnameError")).size() > 0); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + @RunAsClient |
| 94 | + public void givenSurname_whenSurnameMaxLenghtInvalid_thenErrorMessage() throws Exception { |
| 95 | + browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); |
| 96 | + averageInput.sendKeys("aaaaabbbbbc"); |
| 97 | + guardHttp(sendButton).click(); |
| 98 | + Assert.assertTrue("Show Surname error message", browser.findElements(By.id("myForm:surnameError")).size() > 0); |
| 99 | + } |
| 100 | + |
| 101 | +} |
0 commit comments