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 org.junit.Test;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
29 import org.openqa.selenium.chrome.ChromeDriver;
30 import org.openqa.selenium.firefox.FirefoxDriver;
31 import org.openqa.selenium.ie.InternetExplorerDriver;
32 import org.openqa.selenium.remote.DesiredCapabilities;
33 import org.openqa.selenium.remote.RemoteWebDriver;
34 import org.openqa.selenium.safari.SafariDriver;
37 import java.io.FileInputStream;
38 import java.io.IOException;
39 import java.net.MalformedURLException;
41 import java.util.Properties;
42 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 WebDriverTest
55 public Fluent takeScreenShot(String fileName) {
57 // save html to have a minimum feedback if jenkins firefox not up
58 File fileNameHTML = new File(fileName + ".html");
59 FileUtils.writeStringToFile(fileNameHTML, getDriver().getPageSource());
60 } catch (IOException e) {
61 System.out.print(e.getMessage());
64 return super.takeScreenShot(fileName);
69 setSnapshotMode(Mode.TAKE_SNAPSHOT_ON_FAIL);
70 setSnapshotPath(new File("target", "errorshtmlsnap").getAbsolutePath());
74 public void simpletest()
77 Properties tomcatPortProperties = new Properties();
78 tomcatPortProperties.load(
79 new FileInputStream(new File(System.getProperty("tomcat.propertiesPortFilePath"))));
81 int tomcatPort = Integer.parseInt(tomcatPortProperties.getProperty("tomcat.maven.http.port"));
83 goTo("http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en");
85 // wait until topbar-menu-container is feeded
86 await().atMost(5, TimeUnit.SECONDS).until("#topbar-menu").isPresent();
88 FluentList<FluentWebElement> elements = find("#create-admin-link-a");
90 if (!elements.isEmpty() && elements.get(0).isDisplayed()) {
91 WebElement webElement = elements.get(0).getElement();
92 Assert.assertEquals("Create Admin User", webElement.getText());
94 elements = find("#login-link-a");
95 WebElement webElement = elements.get(0).getElement();
96 Assert.assertEquals("LOGIN", webElement.getText());
102 public WebDriver getDefaultDriver() {
103 String seleniumBrowser = System.getProperty("selenium.browser");
104 String seleniumHost = System.getProperty("seleniumHost", "localhost");
105 int seleniumPort = Integer.getInteger("seleniumPort", 4444);
108 if (StringUtils.contains(seleniumBrowser, "chrome")) {
109 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
110 DesiredCapabilities.chrome()
114 if (StringUtils.contains(seleniumBrowser, "safari")) {
115 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
116 DesiredCapabilities.safari()
120 if (StringUtils.contains(seleniumBrowser, "iexplore")) {
121 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
122 DesiredCapabilities.internetExplorer()
126 return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
127 DesiredCapabilities.firefox()
129 } catch (MalformedURLException e) {
130 throw new RuntimeException("Initializion of remote driver failed");