Skip to content

Commit

Permalink
Merge 95338f3 into 7b8b8e6
Browse files Browse the repository at this point in the history
  • Loading branch information
filipcynarski committed Apr 2, 2016
2 parents 7b8b8e6 + 95338f3 commit 19121b9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.fluentlenium.core;

import org.fluentlenium.core.annotation.PageUrl;
import org.openqa.selenium.WebDriver;

/**
Expand All @@ -21,6 +22,12 @@ public FluentPage(WebDriver driver) {
* @return page URL
*/
public String getUrl() {
if (this.getClass().isAnnotationPresent(PageUrl.class)) {
String url = this.getClass().getAnnotation(PageUrl.class).value();
if (!url.isEmpty()) {
return url;
}
}
return null;
}

Expand All @@ -40,6 +47,4 @@ public void isAt() {
public final void go() {
goTo(getUrl());
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.fluentlenium.core.annotation;

import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* <b>PageUrl</b> is a class annotation used instead of <b>getUrl</b> method of <b>FluentPage</b> object.
* If <b>PageUrl</b> annotation is used the page class may not override the <b>getUrl</b> method.
*/
@Retention(RUNTIME)
public @interface PageUrl {
/**
* The page URL can be relative or absolute, if the URL is not recognized
* as absolute will be treated as relative.
* <p/>
* For example :
* <code>@PageUrl("/index.html")</code> should redirect to baseUrl + "/index.html"
* <code>@PageUrl("http://example.com")</code> should redirect to "http://example.com"
*
* @return page url
*/
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.fluentlenium.core.FluentPage;
import org.fluentlenium.core.annotation.Page;
import org.fluentlenium.core.annotation.PageUrl;
import org.fluentlenium.integration.localtest.LocalFluentCase;
import org.junit.Test;

Expand All @@ -17,7 +18,7 @@ public class BaseUrlTest extends LocalFluentCase {

@Override
public String getDefaultBaseUrl() {
return DEFAULT_URL;
return DEFAULT_URL_PATH;
}

@Test
Expand Down Expand Up @@ -46,13 +47,8 @@ public void baseUrlShouldNotBeUsedForAbsoluteUrlInPageGo() {

}

@PageUrl("/page2.html")
class Page2Relative extends FluentPage {

@Override
public String getUrl() {
return LocalFluentCase.PAGE_2_URL;
}

@Override
public void isAt() {
assertThat(getDriver().getTitle()).isEqualTo("Page 2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

import static org.fluentlenium.integration.util.UrlUtil.getAbsoluteUrlFromFile;
import static org.fluentlenium.integration.util.UrlUtil.getAbsoluteUrlPathFromFile;

public abstract class LocalFluentCase extends FluentTest {

public static final String DEFAULT_URL;
public static final String DEFAULT_URL_PATH;
public static final String JAVASCRIPT_URL;
public static final String PAGE_2_URL;
public static final String IFRAME_URL;
public static final String ANOTHERPAGE_URL;

static {
DEFAULT_URL = getAbsoluteUrlFromFile("index.html");
DEFAULT_URL_PATH = getAbsoluteUrlPathFromFile("index.html");
JAVASCRIPT_URL = getAbsoluteUrlFromFile("javascript.html");
PAGE_2_URL = getAbsoluteUrlFromFile("page2.html");
IFRAME_URL = getAbsoluteUrlFromFile("iframe.html");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.fluentlenium.integration.util;

import java.io.File;
import java.net.URL;

public final class UrlUtil {
Expand Down Expand Up @@ -27,4 +28,15 @@ public static String getAbsoluteUrlFromFile(final String file) {

return url.toString();
}

/**
* Removes file name from URL string
*
* @param file the file String
* @return the URL String
*/
public static String getAbsoluteUrlPathFromFile(final String file) {
String url = getAbsoluteUrlFromFile(file);
return url.substring(0, url.lastIndexOf(File.separator));
}
}

0 comments on commit 19121b9

Please sign in to comment.