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

File EntryEditPage.java

 

Coverage histogram

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

Code metrics

0
10
5
1
101
39
5
0.5
2
5
1

Classes

Class Line # Actions
EntryEditPage 38 10 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 5 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 java.util.ArrayList;
23    import java.util.List;
24   
25    import org.apache.commons.lang3.StringUtils;
26    import org.openqa.selenium.By;
27    import org.openqa.selenium.WebElement;
28    import org.xwiki.test.ui.po.FormElement;
29    import org.xwiki.test.ui.po.InlinePage;
30    import org.xwiki.test.ui.po.editor.wysiwyg.EditorElement;
31   
32    /**
33    * Represents the actions possible when editing an application entry.
34    *
35    * @version $Id: e1933ecd51f1a129450ff1dc2abb51d70ee0995f $
36    * @since 4.2M1
37    */
 
38    public class EntryEditPage extends InlinePage
39    {
40    /**
41    * The XPath that locates the label of a form field.
42    * <p>
43    * NOTE: We use a workaround for the fact that ends-with XPath function is not implemented:
44    *
45    * <pre>
46    * {@code substring(@id, string-length(@id) - string-length(suffix) + 1)}
47    * </pre>
48    */
49    private static final String LABEL_XPATH_FORMAT = "//label[substring(@for, string-length(@for) - %s - 2) = '_0_%s']";
50   
51    /**
52    * Retrieves the label of the specified form field.
53    *
54    * @param fieldName the name of a form field
55    * @return the label of the specified form field
56    */
 
57  2 toggle public String getLabel(String fieldName)
58    {
59  2 String xpath = String.format(LABEL_XPATH_FORMAT, fieldName.length(), fieldName);
60  2 WebElement label = getForm().findElement(By.xpath(xpath));
61  2 return label.getText();
62    }
63   
64    /**
65    * @return the list of form field names available on this page
66    */
 
67  3 toggle public List<String> getFieldNames()
68    {
69  3 List<String> fieldNames = new ArrayList<String>();
70  3 for (WebElement field : getForm().findElements(By.xpath("//*[contains(@name, '_0_')]"))) {
71  5 fieldNames.add(StringUtils.substringAfter(field.getAttribute("name"), "_0_"));
72    }
73  3 return fieldNames;
74    }
75   
76    /**
77    * Sets the entry title, if the application class has a Title field.
78    *
79    * @param title the entry title
80    */
 
81  3 toggle public void setTitle(String title)
82    {
83  3 new FormElement(getForm()).setFieldValue(By.name("title"), title);
84    }
85   
86    /**
87    * @return the value of the title input
88    */
 
89  1 toggle public String getTitle()
90    {
91  1 return getForm().findElement(By.name("title")).getAttribute("value");
92    }
93   
94    /**
95    * @return the content editor
96    */
 
97  1 toggle public EditorElement getContentEditor()
98    {
99  1 return new EditorElement("content");
100    }
101    }