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

File AddTagsPane.java

 

Coverage histogram

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

Code metrics

0
9
5
1
111
47
5
0.56
1.8
5
1

Classes

Class Line # Actions
AddTagsPane 35 9 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 9 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.tag.test.po;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.WebDriver;
24    import org.openqa.selenium.WebElement;
25    import org.openqa.selenium.support.FindBy;
26    import org.openqa.selenium.support.ui.ExpectedCondition;
27    import org.xwiki.test.ui.po.BaseElement;
28   
29    /**
30    * Models the panel that is displayed when we want to add new tags to a wiki page.
31    *
32    * @version $Id: f8925235aa505e45fd86281f42c670b459549fbd $
33    * @since 4.2M1
34    */
 
35    public class AddTagsPane extends BaseElement
36    {
37    /**
38    * The class name applied to the add tags HTML form.
39    */
40    private static final String FORM_CLASS_NAME = "tag-add-form";
41   
42    /**
43    * The input field used to enter tags.
44    */
45    @FindBy(id = "tag")
46    private WebElement tagsInput;
47   
48    /**
49    * The HTML form used to add new tags.
50    */
51    @FindBy(className = FORM_CLASS_NAME)
52    private WebElement addTagsForm;
53   
54    /**
55    * The XPATH expression used to locate the add button inside the {@link #addTagsForm}.
56    */
57    private By addButtonLocator = By.xpath("//form[@class = 'tag-add-form']//input[@type = 'submit']");
58   
59    /**
60    * @param tags comma separated list of tags to add
61    */
 
62  12 toggle public void setTags(String tags)
63    {
64  12 tagsInput.clear();
65  12 tagsInput.sendKeys(tags);
66    }
67   
68    /**
69    * Click on the add button to add the typed tags.
70    *
71    * @return {@code true} if any of the typed tags have been added, {@code false} if an error occurs such as an
72    * existing tag is saved.
73    */
 
74  11 toggle public boolean add()
75    {
76    // Wait for no error notifications to be displayed because after that we wait for one to show up.
77  11 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
78    {
 
79  11 toggle @Override
80    public Boolean apply(WebDriver driver)
81    {
82  11 return getDriver().findElements(By.className("xnotification-error")).size() == 0;
83    }
84    });
85   
86  11 addTagsForm.findElement(addButtonLocator).click();
87   
88    // Wait until the add tags panel disappears or
89    // an error notification is shown to indicate something is wrong and the tag cannot be saved.
90  11 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
91    {
 
92  22 toggle @Override
93    public Boolean apply(WebDriver driver)
94    {
95  22 return getDriver().findElements(By.className(FORM_CLASS_NAME)).size() == 0
96    || getDriver().findElements(By.className("xnotification-error")).size() > 0;
97    }
98    });
99   
100    // If the add tags panel is still visible then there was a problem adding the tags.
101  11 return getDriver().findElementsWithoutWaiting(By.className(FORM_CLASS_NAME)).size() == 0;
102    }
103   
104    /**
105    * Click on the cancel button to close the panel.
106    */
 
107  2 toggle public void cancel()
108    {
109  2 addTagsForm.findElement(By.xpath("//form[@class = 'tag-add-form']//input[@type = 'reset']")).click();
110    }
111    }