package org.apache.archiva.web.test;
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import junit.framework.Assert;
import org.apache.commons.lang3.StringUtils;
import org.fluentlenium.adapter.FluentTest;
import org.fluentlenium.core.domain.FluentList;
import org.fluentlenium.core.domain.FluentWebElement;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.safari.SafariDriver;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

/**
 * @author Olivier Lamy
 */
public class WebDriverTest
    extends FluentTest
{

    @Test
    public void simpletest()
        throws Exception
    {

        Properties tomcatPortProperties = new Properties();
        tomcatPortProperties.load(
            new FileInputStream( new File( System.getProperty( "tomcat.propertiesPortFilePath" ) ) ) );

        int tomcatPort = Integer.parseInt( tomcatPortProperties.getProperty( "tomcat.maven.http.port" ) );

        goTo( "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en" );

        FluentList<FluentWebElement> elements = find( "#create-admin-link-a" );

        if ( !elements.isEmpty() && elements.get( 0 ).isDisplayed() )
        {
            WebElement webElement = elements.get( 0 ).getElement();
            Assert.assertEquals( "Create Admin User", webElement.getText() );
        }
        else
        {
            elements = find( "#login-link-a" );
            WebElement webElement = elements.get( 0 ).getElement();
            Assert.assertEquals( "LOGIN", webElement.getText() );
        }

    }

    @Override
    public WebDriver getDefaultDriver()
    {
        String seleniumBrowser = System.getProperty( "selenium.browser" );

        if ( StringUtils.contains( seleniumBrowser, "chrome" ) )
        {
            return new ChromeDriver();
        }

        if ( StringUtils.contains( seleniumBrowser, "safari" ) )
        {
            return new SafariDriver();
        }

        if ( StringUtils.contains( seleniumBrowser, "iexplore" ) )
        {
            return new InternetExplorerDriver();
        }

        return new FirefoxDriver();

    }
}

@@ -1429,110 +1429,957 @@
 ava.
-util.Properties;%0A%0A/**%0A * @author Olivier Lamy%0A */%0Apublic class WebDriverTest%0A    extends FluentTest%0A%7B%0A
+io.IOException;%0Aimport java.util.Properties;%0Aimport org.apache.commons.io.FileUtils;%0Aimport org.fluentlenium.core.Fluent;%0Aimport org.junit.Before;%0A%0A/**%0A * @author Olivier Lamy%0A */%0Apublic class WebDriverTest%0A    extends FluentTest%0A%7B%0A%0A    @Override%0A    public Fluent takeScreenShot( String fileName )%0A    %7B%0A        try%0A        %7B%0A            // save html to have a minimum feedback if jenkins firefox not up%0A            File fileNameHTML = new File( fileName + %22.html%22 );%0A            FileUtils.writeStringToFile( fileNameHTML, getDriver().getPageSource() );%0A        %7D%0A        catch ( IOException e )%0A        %7B%0A            System.out.print( e.getMessage() );%0A            e.printStackTrace();%0A        %7D%0A        return super.takeScreenShot( fileName );%0A    %7D%0A    %0A    @Before%0A    public void init()%0A    %7B%0A        setSnapshotMode( Mode.TAKE_SNAPSHOT_ON_FAIL );%0A        setSnapshotPath( new File( %22target%22, %22errorshtmlsnap%22 ).getAbsolutePath() );%0A    %7D%0A    
 %0A   
@@ -2445,16 +2445,24 @@
 n%0A    %7B%0A
+        
 %0A       

add page source capture for fluent content may not be accurate