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-199: Provide a way to create Page Fragments dynamically #72

Merged
merged 1 commit into from
Feb 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
import java.util.List;

/**
* PageFragments represents a container for Page Fragments, in other words a page fragment which can contain other page
* fragments, which you can easily access.
*
* @author <a href="mailto:jhuska@redhat.com">Juraj Huska</a>
*
*/
public interface ComponentsContainer<T> {

List<NestedElements<T>> getContent();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
package org.jboss.arquillian.graphene.component.object.api.popup;

import org.jboss.arquillian.graphene.component.object.api.common.ComponentsContainer;
import org.jboss.arquillian.graphene.component.object.api.switchable.SwitchableComponent;

/**
* <p>
Expand All @@ -35,7 +35,7 @@
* @author <a href="mailto:jhuska@redhat.com">Juraj Huska</a>
*
*/
public interface PopupComponent<T> extends ComponentsContainer<T> {
public interface PopupComponent extends SwitchableComponent {

/**
* Returns whether this popup is visible.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2012, 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.component.object.api.switchable;

/**
*
* @author <a href="mailto:jhuska@redhat.com">Juraj Huska</a>
*
*/
public interface ComponentContainer {

<T> T getContent(Class<T> clazz);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2012, 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.component.object.api.switchable;


/**
*
* @author <a href="mailto:jhuska@redhat.com">Juraj Huska</a>
*
*/
public interface SwitchableComponent {

ComponentContainer switchTo(int i);
}
12 changes: 10 additions & 2 deletions graphene-webdriver/graphene-webdriver-ftest/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -55,6 +56,13 @@
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-component-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -94,7 +102,7 @@
<browser>firefox</browser>
</properties>
</profile>

<profile>
<id>webdriver-opera</id>
<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.enricher;

import static org.junit.Assert.assertEquals;

import java.net.URL;

import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.enricher.findby.FindBy;
import org.jboss.arquillian.graphene.enricher.page.fragment.Panel;
import org.jboss.arquillian.graphene.enricher.page.fragment.TabPanel;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

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

@Drone
private WebDriver browser;

@FindBy(className = "tabpanel")
private TabPanel tabPanel;

@Before
public void loadPage() {
URL page = this.getClass().getClassLoader()
.getResource("org/jboss/arquillian/graphene/ftest/enricher/container-elements.html");
browser.get(page.toString());
}

@Test
public void testTabPanelSwitching() {
Panel tab3 = tabPanel.switchTo(2);
ContentOfTab content = tab3.getContent(ContentOfTab.class);
assertEquals("The tab panel was not switched to third tab correctly!", "Content of the tab 3", content.text.getText());

Panel tab1 = tabPanel.switchTo(0);
content = tab1.getContent(ContentOfTab.class);
assertEquals("The tab panel was not switched to first tab correctly!", "Content of the tab 1", content.text.getText());
}

private static class ContentOfTab {

@FindBy(className = "tab-text")
public WebElement text;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.enricher.page.fragment;

import org.jboss.arquillian.graphene.component.object.api.switchable.ComponentContainer;
import org.jboss.arquillian.graphene.enricher.PageFragmentEnricher;
import org.jboss.arquillian.graphene.spi.annotations.Root;
import org.openqa.selenium.WebElement;

/**
* @author <a href="mailto:jhuska@redhat.com">Juraj Huska</a>
*/
public class Panel implements ComponentContainer {

@Root
private WebElement root;

@Override
public <T> T getContent(Class<T> clazz) {
return PageFragmentEnricher.createPageFragment(clazz, root);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2011, 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.enricher.page.fragment;

import static org.jboss.arquillian.graphene.Graphene.guardHttp;
import static org.jboss.arquillian.graphene.Graphene.guardXhr;

import java.util.List;

import org.jboss.arquillian.graphene.Graphene;
import org.jboss.arquillian.graphene.component.object.api.switchable.SwitchableComponent;
import org.jboss.arquillian.graphene.enricher.findby.FindBy;
import org.openqa.selenium.WebElement;

/**
* @author <a href="mailto:jhuska@redhat.com">Juraj Huska</a>
*/
public class TabPanel implements SwitchableComponent {

@FindBy(className = "tabpanel-tab-inact")
private List<WebElement> tabs;

@FindBy(jquery = ".tabpanel-tab:visible")
private Panel actualTab;

private SwitchType switchType = SwitchType.CLIENT;

public enum SwitchType {
CLIENT,
AJAX,
HTTP
}

@Override
public Panel switchTo(int i) {
switch (switchType) {
case CLIENT:
tabs.get(i).click();
Graphene.waitGui();
break;
case AJAX:
guardXhr(tabs.get(i)).click();
break;
case HTTP:
guardHttp(tabs.get(i)).click();
break;
}

return actualTab;
}

public void setSwitchType(SwitchType switchType) {
this.switchType = switchType;
}

}