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.fest.assertions.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.safari.SafariDriver;
36 import java.io.FileInputStream;
37 import java.io.IOException;
38 import java.util.Properties;
39 import java.util.concurrent.TimeUnit;
40 import org.apache.commons.io.FileUtils;
41 import org.fluentlenium.core.Fluent;
42 import org.junit.Before;
45 * @author Olivier Lamy
47 public class WebDriverBrowseTest
52 public Fluent takeScreenShot( String fileName )
54 File fileNameHTML = new File( "target", "errorshtmlsnap" );
57 // save html to have a minimum feedback if jenkins firefox not up
58 fileNameHTML = new File( fileNameHTML, fileName );
59 FileUtils.writeStringToFile( new File ( new File( "target", "errorshtmlsnap" ) , fileName + ".html"), getDriver().getPageSource() );
62 catch ( IOException e )
66 return super.takeScreenShot( fileNameHTML.getAbsolutePath() );
73 setSnapshotMode( Mode.TAKE_SNAPSHOT_ON_FAIL );
77 public void simpletest()
80 Properties p = new Properties();
81 p.load( this.getClass().getClassLoader().getResourceAsStream( "test.properties" ) );
83 Properties tomcatPortProperties = new Properties();
84 tomcatPortProperties.load(
85 new FileInputStream( new File( System.getProperty( "tomcat.propertiesPortFilePath" ) ) ) );
87 int tomcatPort = Integer.parseInt( tomcatPortProperties.getProperty( "tomcat.maven.http.port" ) );
89 goTo( "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en" );
91 // wait until topbar-menu-container is feeded
92 await().atMost( 5, TimeUnit.SECONDS ).until( "#topbar-menu" ).isPresent();
94 FluentList<FluentWebElement> elements = find( "#create-admin-link-a" );
96 if ( !elements.isEmpty() && elements.get( 0 ).isDisplayed() )
98 WebElement webElement = elements.get( 0 ).getElement();
99 Assert.assertEquals( "Create Admin User", webElement.getText() );
102 await().atMost( 2, TimeUnit.SECONDS ).until( "#user-create" ).isPresent();
103 assertThat( find( "#username" ).getValue().equals( "admin" ) );
104 assertThat( find( "#password" ).getValue().isEmpty() );
105 assertThat( find( "#confirmPassword" ).getValue().isEmpty() );
106 assertThat( find( "#email" ).getValue().isEmpty() );
108 fill( "#fullname" ).with( p.getProperty( "ADMIN_FULLNAME" ) );
109 fill( "#email" ).with( p.getProperty( "ADMIN_EMAIL" ) );
110 fill( "#password" ).with( p.getProperty( "ADMIN_PASSWORD" ) );
111 fill( "#confirmPassword" ).with( p.getProperty( "ADMIN_PASSWORD" ) );
112 find( "#user-create-form-register-button" ).click();
114 await().atMost( 2, TimeUnit.SECONDS ).until( "#logout-link" ).isPresent();
116 FluentList<FluentWebElement> elementss = find( "#menu-find-browse-a" );
117 WebElement webElsement = elementss.get( 0 ).getElement();
119 await().atMost( 2, TimeUnit.SECONDS ).until( "#main_browse_result" ).isPresent();
120 // give me search page :( not browse page
122 takeScreenShot( "search.png" );
124 goTo( "http://localhost:" + tomcatPort + "/archiva/index.html#browse?request_lang=en" );
125 takeScreenShot( "browse.png" );
126 // give me a browse page
131 elements = find( "#login-link-a" );
132 WebElement webElement = elements.get( 0 ).getElement();
133 Assert.assertEquals( "LOGIN", webElement.getText() );
139 public WebDriver getDefaultDriver()
141 String seleniumBrowser = System.getProperty( "selenium.browser" );
143 if ( StringUtils.contains( seleniumBrowser, "chrome" ) )
145 return new ChromeDriver();
148 if ( StringUtils.contains( seleniumBrowser, "safari" ) )
150 return new SafariDriver();
153 if ( StringUtils.contains( seleniumBrowser, "iexplore" ) )
155 return new InternetExplorerDriver();
158 return new FirefoxDriver();