1 package org.apache.archiva.web.test;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import junit.framework.Assert;
22 import org.apache.commons.lang3.StringUtils;
23 import org.fluentlenium.adapter.FluentTest;
24 import org.fluentlenium.core.domain.FluentList;
25 import org.fluentlenium.core.domain.FluentWebElement;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import org.junit.Test;
28 import org.openqa.selenium.WebDriver;
29 import org.openqa.selenium.WebElement;
30 import org.openqa.selenium.chrome.ChromeDriver;
31 import org.openqa.selenium.firefox.FirefoxDriver;
32 import org.openqa.selenium.ie.InternetExplorerDriver;
33 import org.openqa.selenium.remote.DesiredCapabilities;
34 import org.openqa.selenium.remote.RemoteWebDriver;
35 import org.openqa.selenium.safari.SafariDriver;
38 import java.io.FileInputStream;
39 import java.io.IOException;
40 import java.net.MalformedURLException;
42 import java.util.Properties;
43 import java.util.concurrent.TimeUnit;
44 import org.apache.commons.io.FileUtils;
45 import org.fluentlenium.core.Fluent;
46 import org.junit.Before;
49 * @author Olivier Lamy
51 public class WebDriverBrowseTest
56 public Fluent takeScreenShot( String fileName )
58 File fileNameHTML = new File( "target", "errorshtmlsnap" );
61 // save html to have a minimum feedback if jenkins firefox not up
62 fileNameHTML = new File( fileNameHTML, fileName );
63 FileUtils.writeStringToFile( new File ( new File( "target", "errorshtmlsnap" ) , fileName + ".html"), getDriver().getPageSource() );
66 catch ( IOException e )
70 return super.takeScreenShot( fileNameHTML.getAbsolutePath() );
77 setSnapshotMode( Mode.TAKE_SNAPSHOT_ON_FAIL );
81 public void simpletest()
84 Properties p = new Properties();
85 p.load( this.getClass().getClassLoader().getResourceAsStream( "test.properties" ) );
87 Properties tomcatPortProperties = new Properties();
88 tomcatPortProperties.load(
89 new FileInputStream( new File( System.getProperty( "tomcat.propertiesPortFilePath" ) ) ) );
91 int tomcatPort = Integer.parseInt( tomcatPortProperties.getProperty( "tomcat.maven.http.port" ) );
93 goTo( "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en" );
95 // wait until topbar-menu-container is feeded
96 await().atMost( 5, TimeUnit.SECONDS ).until( "#topbar-menu" ).isPresent();
98 FluentList<FluentWebElement> elements = find( "#create-admin-link-a" );
100 if ( !elements.isEmpty() && elements.get( 0 ).isDisplayed() )
102 WebElement webElement = elements.get( 0 ).getElement();
103 Assert.assertEquals( "Create Admin User", webElement.getText() );
106 await().atMost( 2, TimeUnit.SECONDS ).until( "#user-create" ).isPresent();
107 assertThat( find( "#username" ).getValue().equals( "admin" ) );
108 assertThat( find( "#password" ).getValue().isEmpty() );
109 assertThat( find( "#confirmPassword" ).getValue().isEmpty() );
110 assertThat( find( "#email" ).getValue().isEmpty() );
112 fill( "#fullname" ).with( p.getProperty( "ADMIN_FULLNAME" ) );
113 fill( "#email" ).with( p.getProperty( "ADMIN_EMAIL" ) );
114 fill( "#password" ).with( p.getProperty( "ADMIN_PASSWORD" ) );
115 fill( "#confirmPassword" ).with( p.getProperty( "ADMIN_PASSWORD" ) );
116 find( "#user-create-form-register-button" ).click();
118 await().atMost( 2, TimeUnit.SECONDS ).until( "#logout-link" ).isPresent();
120 FluentList<FluentWebElement> elementss = find( "#menu-find-browse-a" );
121 WebElement webElsement = elementss.get( 0 ).getElement();
123 await().atMost( 2, TimeUnit.SECONDS ).until( "#main_browse_result" ).isPresent();
124 // give me search page :( not browse page
126 takeScreenShot( "search.png" );
128 goTo( "http://localhost:" + tomcatPort + "/archiva/index.html#browse?request_lang=en" );
129 takeScreenShot( "browse.png" );
130 // give me a browse page
135 elements = find( "#login-link-a" );
136 WebElement webElement = elements.get( 0 ).getElement();
137 Assert.assertEquals( "LOGIN", webElement.getText() );
143 public WebDriver getDefaultDriver() {
144 String seleniumBrowser = System.getProperty("selenium.browser");
145 String seleniumHost = System.getProperty("seleniumHost", "localhost");
146 int seleniumPort = Integer.getInteger("seleniumPort", 4444);
149 if (StringUtils.contains(seleniumBrowser, "chrome")) {
150 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
151 DesiredCapabilities.chrome()
155 if (StringUtils.contains(seleniumBrowser, "safari")) {
156 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
157 DesiredCapabilities.safari()
161 if (StringUtils.contains(seleniumBrowser, "iexplore")) {
162 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
163 DesiredCapabilities.internetExplorer()
167 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
168 DesiredCapabilities.firefox()
170 } catch (MalformedURLException e) {
171 throw new RuntimeException("Initializion of remote driver failed");