1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.index.test.po

File SpacesMacroPane.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
15
3
1
102
43
4
0.27
5
3
1.33

Classes

Class Line # Actions
SpacesMacroPane 37 15 0% 4 1
0.9595%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.index.test.po;
21   
22    import java.util.List;
23   
24    import org.openqa.selenium.By;
25    import org.openqa.selenium.WebElement;
26    import org.openqa.selenium.support.FindBy;
27    import org.xwiki.test.ui.po.BaseElement;
28    import org.xwiki.test.ui.po.CreatePagePage;
29    import org.xwiki.test.ui.po.ViewPage;
30   
31    /**
32    * Represents the actions that can be done on the Spaces Macro when executed.
33    *
34    * @version $Id: f63652898088d30bfce27a730db743c714062646 $
35    * @since 7.0RC1
36    */
 
37    public class SpacesMacroPane extends BaseElement
38    {
39    /**
40    * The element that needs to be clicked to show/hide the space creation form.
41    */
42    @FindBy(linkText = "Create a new space")
43    private WebElement spaceCreateFormToggleSwitch;
44   
45    /**
46    * The text field used to input the space name.
47    */
48    @FindBy(id = "spSpaceCreateTextInput")
49    private WebElement spaceNameTextField;
50   
51    /**
52    * Shows the space creation form, fills the space name text field with the given space name and submits the form.
53    *
54    * @param spaceName the name of the space to create
55    * @return the create page form for the space home page
56    */
 
57  1 toggle public CreatePagePage createSpace(String spaceName)
58    {
59  1 this.spaceCreateFormToggleSwitch.click();
60  1 this.spaceNameTextField.clear();
61  1 this.spaceNameTextField.sendKeys(spaceName);
62  1 this.spaceNameTextField.submit();
63  1 return new CreatePagePage();
64    }
65   
 
66  1 toggle public SpaceIndexPage clickSpaceIndex(String spaceName)
67    {
68  1 String escapedSpaceName = getUtil().escapeURL(spaceName);
69   
70    // Start by finding all li elements with 'xitem' class
71  1 for (WebElement liElement : getDriver().findElementsWithoutWaiting(By.xpath("//li[contains(@class, 'xitem')]")))
72    {
73  3 List<WebElement> elements = getDriver().findElementsWithoutWaiting(liElement,
74    By.xpath(".//a[contains(@href, 'SpaceIndex?space=" + escapedSpaceName + "')]"));
75  3 if (!elements.isEmpty()) {
76   
77    // Make sure we hover before we click since the link is hidden by default.
78    // TODO: However since I wasn't able to perform a hover, I'm cheating by removing the class
79    // attribute that makes the element hidden.
80  1 getDriver().executeJavascript("arguments[0].setAttribute('class', '')", liElement);
81   
82    // Click
83  1 elements.get(0).click();
84  1 return new SpaceIndexPage();
85    }
86    }
87   
88  0 throw new RuntimeException("Was unable to click on space index for [" + spaceName + "]");
89    }
90   
91    /**
92    * Clicks on the link to the space home page.
93    *
94    * @param spaceName the space name
95    * @return the page object corresponding to the space home page
96    */
 
97  1 toggle public ViewPage clickSpaceHome(String spaceName)
98    {
99  1 getDriver().findElement(By.xpath("//div[@class = 'spSpaceName']/a[. = '" + spaceName + "']")).click();
100  1 return new ViewPage();
101    }
102    }