Author: olamy Date: Fri Oct 25 04:14:57 2013 New Revision: 1535623 URL: http://svn.apache.org/r1535623 Log: [MTOMCAT-244] Upgrade Archetype Webapp IT Project to Selenium 2.x Submitted by Ryan Highley
Modified: tomcat/maven-plugin/trunk/tomcat-maven-archetype/pom.xml tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/pom.xml tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/src/test/java/webapp/test/SimpleTest.java Modified: tomcat/maven-plugin/trunk/tomcat-maven-archetype/pom.xml URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-archetype/pom.xml?rev=1535623&r1=1535622&r2=1535623&view=diff ============================================================================== --- tomcat/maven-plugin/trunk/tomcat-maven-archetype/pom.xml (original) +++ tomcat/maven-plugin/trunk/tomcat-maven-archetype/pom.xml Fri Oct 25 04:14:57 2013 @@ -38,9 +38,8 @@ <properties> <archetypeVersion>2.2</archetypeVersion> <tomcatPluginVersion>${project.version}</tomcatPluginVersion> - <tomcatPluginSeleniumBrowser>firefox</tomcatPluginSeleniumBrowser> - <archetypeItGoalsBatch>clean,pre-integration-test,-P${tomcatPluginSeleniumBrowser}</archetypeItGoalsBatch> - <archetypeItGoals>clean,install,-P${tomcatPluginSeleniumBrowser}</archetypeItGoals> + <archetypeItGoalsBatch>clean,pre-integration-test</archetypeItGoalsBatch> + <archetypeItGoals>clean,install</archetypeItGoals> </properties> <build> @@ -103,7 +102,7 @@ <version>${archetypeVersion}</version> <configuration> <settingsFile>${basedir}/src/test/test-settings.xml</settingsFile> - <localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath> + <localRepository>${basedir}/target/local-repo</localRepository> </configuration> </plugin> </plugins> @@ -112,8 +111,8 @@ <profile> <id>headless</id> <properties> - <archetypeItGoalsBatch>clean,pre-integration-test,-Pheadless,-P$(tomcatPluginSeleniumBrowser}</archetypeItGoalsBatch> - <archetypeItGoals>clean,install,-Pheadless,,-P$(tomcatPluginSeleniumBrowser}</archetypeItGoals> + <archetypeItGoalsBatch>clean,pre-integration-test,-Pheadless</archetypeItGoalsBatch> + <archetypeItGoals>clean,install,-Pheadless</archetypeItGoals> </properties> </profile> </profiles> Modified: tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/pom.xml URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/pom.xml?rev=1535623&r1=1535622&r2=1535623&view=diff ============================================================================== --- tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/pom.xml (original) +++ tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/pom.xml Fri Oct 25 04:14:57 2013 @@ -31,11 +31,10 @@ <properties> <seleniumPluginVersion>2.3</seleniumPluginVersion> - <selenium-server.version>2.35.0</selenium-server.version> + <selenium-server.version>2.37.0</selenium-server.version> <selenium.port>4444</selenium.port> <tomcat.port>9898</tomcat.port> <serverUrl>http://localhost:${tomcat.port}/</serverUrl> - <seleniumBrowser>*firefox</seleniumBrowser> </properties> <build> @@ -119,9 +118,7 @@ </goals> <configuration> <systemPropertyVariables> - <selenium.port>${selenium.port}</selenium.port> <serverUrl>${serverUrl}</serverUrl> - <seleniumBrowser>${seleniumBrowser}</seleniumBrowser> </systemPropertyVariables> </configuration> </execution> @@ -193,39 +190,15 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.seleniumhq.selenium.client-drivers</groupId> - <artifactId>selenium-java-client-driver</artifactId> - <version>1.0.2</version> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-java</artifactId> + <version>${selenium-server.version}</version> <scope>test</scope> </dependency> </dependencies> <profiles> <profile> - <id>firefox</id> - <properties> - <seleniumBrowser>*firefox</seleniumBrowser> - </properties> - </profile> - <profile> - <id>chrome</id> - <properties> - <seleniumBrowser>*googlechrome</seleniumBrowser> - </properties> - </profile> - <profile> - <id>iexplore</id> - <properties> - <seleniumBrowser>*iexplore</seleniumBrowser> - </properties> - </profile> - <profile> - <id>safari</id> - <properties> - <seleniumBrowser>*safari</seleniumBrowser> - </properties> - </profile> - <profile> <id>headless</id> <build> <plugins> Modified: tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/src/test/java/webapp/test/SimpleTest.java URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/src/test/java/webapp/test/SimpleTest.java?rev=1535623&r1=1535622&r2=1535623&view=diff ============================================================================== --- tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/src/test/java/webapp/test/SimpleTest.java (original) +++ tomcat/maven-plugin/trunk/tomcat-maven-archetype/src/main/resources/archetype-resources/__rootArtifactId__-webapp-it/src/test/java/webapp/test/SimpleTest.java Fri Oct 25 04:14:57 2013 @@ -21,32 +21,67 @@ package ${package}.webapp.test; * under the License. */ -import com.thoughtworks.selenium.DefaultSelenium; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; /** * @author Olivier Lamy */ +@RunWith(JUnit4.class) public class SimpleTest - extends TestCase { - + private WebDriver driver; + private String serverUrl; + + @Before + public void setup() throws Exception + { + this.serverUrl = System.getProperty("serverUrl", "http://localhost:9898/"); + if(!this.serverUrl.endsWith("/")) { + this.serverUrl += "/"; + } + + this.driver = new HtmlUnitDriver(true); // HtmlUnitDriver with JavaScript enabled + } + + @After + public void teardown() throws Exception + { + this.driver.close(); + } + + @Test public void testSimple() throws Exception { - - int seleniumPort = Integer.parseInt( System.getProperty( "selenium.port", "4444" ) ); - String browser = System.getProperty( "seleniumBrowser", "*firefox" ); - String serverUrl = System.getProperty( "serverUrl", "http://localhost:9090/" ); - - DefaultSelenium s = new DefaultSelenium( "localhost", seleniumPort, browser, serverUrl ); - s.start( ); - s.open( "index.html" ); - s.type( "who", "foo" ); - s.click( "send-btn" ); - // wait a bit ajax response - Thread.sleep( 1000 ); - String text = s.getText( "response" ); - assertEquals( "Hello foo", text ); + this.driver.get(this.serverUrl + "index.html"); + + String whoToSend = "foo"; + + WebElement who = this.driver.findElement(By.id("who")); + who.sendKeys(whoToSend); + + WebElement sendBtn = this.driver.findElement(By.id("send-btn")); + sendBtn.click(); + + // wait 5 secs for ajax response + new WebDriverWait(this.driver, 5).until( + ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend) + ); + + WebElement response = this.driver.findElement(By.id("response")); + String text = response.getText(); + + Assert.assertEquals("Hello " + whoToSend, text); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org