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

File ApplicationsLiveTableElement.java

 

Coverage histogram

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

Code metrics

0
23
13
1
168
78
13
0.57
1.77
13
1

Classes

Class Line # Actions
ApplicationsLiveTableElement 34 23 0% 13 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

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.appwithinminutes.test.po;
21   
22    import org.apache.commons.lang.StringUtils;
23    import org.openqa.selenium.By;
24    import org.openqa.selenium.WebElement;
25    import org.xwiki.test.ui.po.ConfirmationPage;
26    import org.xwiki.test.ui.po.LiveTableElement;
27   
28    /**
29    * Represents the live table that lists the existing applications on the AppWithinMinuts home page.
30    *
31    * @version $Id: 388a78f84184184c245107c9852fbe96f029f294 $
32    * @since 4.2M1
33    */
 
34    public class ApplicationsLiveTableElement extends LiveTableElement
35    {
36    /**
37    * Identifies the application name filter input.
38    */
39    private static final String APP_NAME_FILTER_ID = "xwiki-livetable-livetable-filter-1";
40   
41    /**
42    * The title of the live table column that displays the application name.
43    */
44    private static final String APP_NAME_COLUMN_TITLE = "Application name";
45   
46    /**
47    * Creates a new instance.
48    */
 
49  14 toggle public ApplicationsLiveTableElement()
50    {
51  14 super("livetable");
52    }
53   
54    /**
55    * @param appName the name of an application
56    * @return {@code true} if the specified application is listed, {@code false} otherwise
57    */
 
58  2 toggle public boolean isApplicationListed(String appName)
59    {
60  2 return hasRow(APP_NAME_COLUMN_TITLE, appName);
61    }
62   
63    /**
64    * @param appPath the application path
65    * @return {@code true} if the specified application is listed, {@code false} otherwise
66    */
 
67  2 toggle public boolean isApplicationListed(String... appPath)
68    {
69  2 return hasRow(APP_NAME_COLUMN_TITLE, join(appPath));
70    }
71   
 
72  1 toggle public ApplicationHomePage viewApplication(String... path)
73    {
74  1 String escapedPath = getUtil().escapeXPath(join(path));
75  1 getDriver().findElementWithoutWaiting(
76    By.xpath("//td[contains(@class, 'doc_space')]/a[. = " + escapedPath + "]")).click();
77  1 return new ApplicationHomePage();
78    }
79   
 
80  3 toggle private String join(String... path)
81    {
82  3 return StringUtils.join(path, " \u00BB ");
83    }
84   
85    /**
86    * Clicks on the link to delete the specified application.
87    *
88    * @param appName the name of the application to delete
89    */
 
90  2 toggle public ConfirmationPage clickDeleteApplication(String appName)
91    {
92  2 clickAction(appName, "delete");
93  2 return new ConfirmationPage();
94    }
95   
96    /**
97    * @param appName the name of an application
98    * @return {@code true} if the delete link is displayed for the specified application
99    */
 
100  3 toggle public boolean canDeleteApplication(String appName)
101    {
102  3 return hasAction(appName, "delete");
103    }
104   
105    /**
106    * Clicks on the link to edit the specified application.
107    *
108    * @param appName the name of the application to delete.
109    */
 
110  1 toggle public ApplicationClassEditPage clickEditApplication(String appName)
111    {
112  1 clickAction(appName, "edit");
113  1 return new ApplicationClassEditPage();
114    }
115   
116    /**
117    * @param appName the name of an application
118    * @return {@code true} if the edit link is displayed for the specified application
119    */
 
120  3 toggle public boolean canEditApplication(String appName)
121    {
122  3 return hasAction(appName, "edit");
123    }
124   
125    /**
126    * Clicks one of the action links corresponding to the specified application.
127    *
128    * @param appName the action target
129    * @param action the action name
130    */
 
131  3 toggle protected void clickAction(String appName, String action)
132    {
133  3 String escapedAppName = appName.replace("\\", "\\\\").replace("'", "\\'");
134  3 String actionLinkXPath =
135    "//tr[td[contains(@class, 'doc_space') and . = '" + escapedAppName
136    + "']]/td[@class = 'actions']//a[contains(@class, 'action" + action + "')]";
137  3 WebElement liveTableBody = getDriver().findElement(By.id("livetable-display"));
138  3 liveTableBody.findElement(By.xpath(actionLinkXPath)).click();
139    }
140   
141    /**
142    * @return {@code true} if the given action is listed for the specified application, {@code false} otherwise
143    */
 
144  6 toggle protected boolean hasAction(String appName, String action)
145    {
146  6 String escapedAppName = appName.replace("\\", "\\\\").replace("'", "\\'");
147  6 String actionLinkXPath =
148    "//tr[td[contains(@class, 'doc_space') and . = '" + escapedAppName
149    + "']]/td[@class = 'actions']//a[contains(@class, 'action" + action + "')]";
150  6 WebElement liveTableBody = getDriver().findElement(By.id("livetable-display"));
151  6 return liveTableBody.findElements(By.xpath(actionLinkXPath)).size() > 0;
152    }
153   
154    /**
155    * Filters by application name.
156    *
157    * @param appNameFilter the string to filter the application names with
158    */
 
159  4 toggle public void filterApplicationName(String appNameFilter)
160    {
161  4 super.filterColumn(APP_NAME_FILTER_ID, appNameFilter);
162    }
163   
 
164  2 toggle public String getApplicationNameFilter()
165    {
166  2 return super.getFilterValue(APP_NAME_FILTER_ID);
167    }
168    }