Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARQGRA-345: GrapheneElement can not be used as @Root - fixed #90

Merged
merged 1 commit into from
Oct 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
221 changes: 8 additions & 213 deletions api/src/main/java/org/jboss/arquillian/graphene/GrapheneElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,16 @@
*/
package org.jboss.arquillian.graphene;

import java.util.LinkedList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.Point;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.internal.WrapsElement;

/**
* <p>
* Interface for Graphene extensions of {@link WebElement}.
* </p>
*
* <p>
* Following methods are provided over the {@link WebElement} interface:
* </p>
*
* <ul>
* <li>{@link #isPresent()}</li>
* <li>{@link #findGrapheneElements(By)}</li>
* </ul>
*
* <p>
* <b>Important</b>: {@link GrapheneElement} <i>is not intended for extension</i>, do not subclass it. The {@link GrapheneElement} might become abstract class or interface in the future. It can't be final because then it couldn't be proxied by Graphene.
* </p>
*
* @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
*/
public class GrapheneElement implements WebElement, Locatable, WrapsElement {

private final WebElement element;

public GrapheneElement(WebElement element) {
this.element = element;
}
public interface GrapheneElement extends WebElement, Locatable, WrapsElement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the interface.


/**
* <p>
Expand All @@ -77,14 +47,7 @@ public GrapheneElement(WebElement element) {
*
* @return true if this element is present in the page
*/
public boolean isPresent() {
try {
element.isDisplayed();
return true;
} catch (NoSuchElementException ignored) {
return false;
}
}
boolean isPresent();

/**
* This method is alternative to {@link #findElements(By)}, but it returns list of type {@link GrapheneElement}.
Expand All @@ -93,182 +56,14 @@ public boolean isPresent() {
*
* @see WebElement#findElement(By)
*/
public List<GrapheneElement> findGrapheneElements(By by) {
List<GrapheneElement> grapheneElements = new LinkedList<GrapheneElement>();
for (WebElement e : element.findElements(by)) {
grapheneElements.add(new GrapheneElement(e));
}
return grapheneElements;
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#click()
*/
@Override
public void click() {
element.click();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#submit()
*/
@Override
public void submit() {
element.submit();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#sendKeys(java.lang.CharSequence[])
*/
@Override
public void sendKeys(CharSequence... keysToSend) {
element.sendKeys(keysToSend);
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#clear()
*/
@Override
public void clear() {
element.clear();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#getTagName()
*/
@Override
public String getTagName() {
return element.getTagName();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#getAttribute(java.lang.String)
*/
@Override
public String getAttribute(String name) {
return element.getAttribute(name);
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#isSelected()
*/
@Override
public boolean isSelected() {
return element.isSelected();
}
List<GrapheneElement> findGrapheneElements(By by);

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#isEnabled()
*/
@Override
public boolean isEnabled() {
return element.isEnabled();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#getText()
*/
@Override
public String getText() {
return element.getText();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#findElements(org.openqa.selenium.By)
*/
@Override
public List<WebElement> findElements(By by) {
return element.findElements(by);
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#findElement(org.openqa.selenium.By)
*/
@Override
public GrapheneElement findElement(By by) {
return new GrapheneElement(element.findElement(by));
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#isDisplayed()
*/
@Override
public boolean isDisplayed() {
return element.isDisplayed();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#getLocation()
*/
@Override
public Point getLocation() {
return element.getLocation();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#getSize()
*/
@Override
public Dimension getSize() {
return element.getSize();
}

/*
* (non-Javadoc)
*
* @see org.openqa.selenium.WebElement#getCssValue(java.lang.String)
*/
@Override
public String getCssValue(String propertyName) {
return element.getCssValue(propertyName);
}

/*
* (non-Javadoc)
/**
* Overriden version of <code>WebElement.findBy()</code> method.
*
* @see org.openqa.selenium.internal.WrapsElement#getWrappedElement()
*/
@Override
public WebElement getWrappedElement() {
return element;
}

/*
* (non-Javadoc)
* @return GrapheneElement
*
* @see org.openqa.selenium.internal.Locatable#getCoordinates()
* @see WebElement#findElement(By)
*/
@Override
public Coordinates getCoordinates() {
return ((Locatable) element).getCoordinates();
}

GrapheneElement findElement(By by);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ARQGRA269TestCase {
public class ARQGRA269 {

@ArquillianResource
private URL contextRoot;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.arquillian.graphene.ftest.issues;

import static org.junit.Assert.assertEquals;

import java.net.URL;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.GrapheneElement;
import org.jboss.arquillian.graphene.fragment.Root;
import org.jboss.arquillian.graphene.ftest.Resource;
import org.jboss.arquillian.graphene.ftest.Resources;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.FindBy;

/**
* @author <a href="mailto:jhuska@redhat.com">Juraj Huska</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ARQGRA345 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please rename the test cases meaningfully and structure them appropriately to respective test packages?


@ArquillianResource
private URL contextRoot;

@Drone
private WebDriver browser;

@FindBy(id = "root")
private PageFragmentWithGrapheneElementAsRoot fragment;

private static final String SAMPLE_PACKAGE = "org.jboss.arquillian.graphene.ftest.enricher";

@Deployment
public static WebArchive createTestArchive() {
return Resources.inPackage(SAMPLE_PACKAGE).all().buildWar("test.war");
}

@Before
public void loadPage() {
Resource.inPackage(SAMPLE_PACKAGE).find("sample.html").loadPage(browser, contextRoot);
}

@Test
public void graphene_element_should_be_able_to_be_used_as_root_of_page_fragment() {
assertEquals(fragment.getInnerElement().getText(), "pseudo root");
}

public class PageFragmentWithGrapheneElementAsRoot {

@Root
private GrapheneElement root;

@FindBy(id = "pseudoroot")
private GrapheneElement innerElement;

public GrapheneElement getInnerElement() {
return innerElement;
}

public GrapheneElement getRoot() {
return root;
}
}
}