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 org.fluentlenium.adapter.junit.After;
22 import org.junit.Assert;
23 import org.apache.archiva.web.test.tools.WebdriverUtility;
24 import org.apache.commons.io.FileUtils;
25 import org.fluentlenium.adapter.junit.FluentTest;
26 import org.fluentlenium.configuration.ConfigurationProperties;
27 import org.fluentlenium.configuration.FluentConfiguration;
28 import org.fluentlenium.core.domain.FluentList;
29 import org.fluentlenium.core.domain.FluentWebElement;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.openqa.selenium.By;
33 import org.openqa.selenium.JavascriptExecutor;
34 import org.openqa.selenium.WebDriver;
35 import org.openqa.selenium.WebElement;
36 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 import java.io.IOException;
42 import java.nio.file.Files;
43 import java.nio.file.Path;
44 import java.nio.file.Paths;
47 * @author Olivier Lamy
49 @FluentConfiguration(driverLifecycle = ConfigurationProperties.DriverLifecycle.CLASS)
50 public class WebDriverTest
54 final Logger log = LoggerFactory.getLogger( WebDriverTest.class );
57 public void takeScreenShot( String fileName )
59 log.info("Taking screenshot "+fileName);
60 WebdriverUtility.takeScreenShot( fileName, getDriver());
64 protected void failed( String testName )
66 takeScreenShot( testName + ".png" );
70 public boolean canTakeScreenShot()
77 setScreenshotMode(TriggerMode.AUTOMATIC_ON_FAIL);
78 setScreenshotPath( Paths.get("target", "errorshtmlsnap").toAbsolutePath().toString());
79 setDriverLifecycle( DriverLifecycle.CLASS );
83 public void simpletest()
86 String url = WebdriverUtility.getBaseUrl()+ "/index.html?request_lang=en";
89 // wait until topbar-menu-container is feeded
90 //await().atMost(20, TimeUnit.SECONDS).until($("#topbar-menu")).present();
91 await().untilPredicate((fl) ->$("#topbar-menu").present());
92 FluentList<FluentWebElement> elements = find("#create-admin-link-a");
94 if (!elements.isEmpty() && elements.get(0).displayed()) {
95 WebElement webElement = elements.get(0).getElement();
96 Assert.assertEquals("Create Admin User", webElement.getText());
98 elements = find( By.id("login-link-a"));
99 for(FluentWebElement element : elements) {
100 log.info("Found login link: "+element.getElement().getTagName()+ " "+ element.getElement().getText());
102 WebElement webElement = elements.get(0).getElement();
103 if (getDriver() instanceof HtmlUnitDriver ) {
104 Assert.assertEquals( "LOGIN", webElement.getText().toUpperCase() );
107 Assert.assertEquals( "LOGIN", webElement.getText() );
115 public WebDriver newWebDriver() {
116 return WebdriverUtility.newWebDriver();