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

File ApplicationClassEditPage.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
19
7
1
139
68
10
0.53
2.71
7
1.43

Classes

Class Line # Actions
ApplicationClassEditPage 39 19 0% 10 3
0.8928571389.3%
 

Contributing tests

This file is covered by 30 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.openqa.selenium.By;
23    import org.openqa.selenium.Keys;
24    import org.openqa.selenium.NotFoundException;
25    import org.openqa.selenium.StaleElementReferenceException;
26    import org.openqa.selenium.WebDriver;
27    import org.openqa.selenium.WebElement;
28    import org.openqa.selenium.interactions.Actions;
29    import org.openqa.selenium.support.FindBy;
30    import org.openqa.selenium.support.ui.ExpectedCondition;
31   
32    /**
33    * Represents the actions available when editing the application class. This is also the second step of the App Within
34    * Minutes wizard, in which the application structure defined.
35    *
36    * @version $Id: 120056a05d516f758e77f5c0e3ad28e33356d26b $
37    * @since 4.2M1
38    */
 
39    public class ApplicationClassEditPage extends ApplicationEditPage
40    {
41    @FindBy(id = "palette")
42    private WebElement palette;
43   
44    @FindBy(id = "fields")
45    private WebElement fields;
46   
47    @FindBy(id = "canvas")
48    private WebElement fieldsCanvas;
49   
50    @FindBy(id = "updateClassSheet")
51    private WebElement updateClassSheetCheckbox;
52   
53    /**
54    * Clicks on the Next Step button.
55    *
56    * @return the page that represents the next step of the App Within Minutes wizard
57    */
 
58  11 toggle public ApplicationTemplateProviderEditPage clickNextStep()
59    {
60  11 nextStepButton.click();
61  11 return new ApplicationTemplateProviderEditPage();
62    }
63   
64    /**
65    * Clicks on the Previous Step button.
66    *
67    * @return the page that represents the previous step of the App Within Minutes wizard
68    */
 
69  1 toggle public ApplicationCreatePage clickPreviousStep()
70    {
71  1 previousStepButton.click();
72  1 return new ApplicationCreatePage();
73    }
74   
75    /**
76    * @return {@code true} if the Previous Step button is present, {@code false} otherwise
77    */
 
78  1 toggle public boolean hasPreviousStep()
79    {
80  1 return getDriver().findElementsWithoutWaiting(By.linkText("Previous Step")).size() > 0;
81    }
82   
83    /**
84    * Drags a field of the specified type from the field palette to the field canvas.
85    *
86    * @param fieldType the type of field to add, as displayed on the field palette
87    */
 
88  42 toggle public ClassFieldEditPane addField(String fieldType)
89    {
90  42 String fieldXPath = "//span[@class = 'field' and normalize-space(.) = '%s']";
91  42 WebElement field = palette.findElement(By.xpath(String.format(fieldXPath, fieldType)));
92    // NOTE: We scroll the page up because the drag&drop fails sometimes if the dragged field and the canvas (drop
93    // target) are not fully visible. See https://code.google.com/p/selenium/issues/detail?id=3075 .
94  42 palette.sendKeys(Keys.HOME);
95  42 new Actions(getDriver()).dragAndDrop(field, fieldsCanvas).perform();
96  42 final WebElement addedField = fieldsCanvas.findElement(By.xpath("./ul[@id='fields']/li[last()]"));
97   
98  42 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
99    {
 
100  81 toggle @Override
101    public Boolean apply(WebDriver driver)
102    {
103  81 try {
104  81 return !addedField.getAttribute("class").contains("loading");
105    } catch (NotFoundException e) {
106  0 return false;
107    } catch (StaleElementReferenceException e) {
108    // The element was removed from DOM in the meantime
109  0 return false;
110    }
111    }
112    });
113   
114  42 return new ClassFieldEditPane(addedField.getAttribute("id").substring("field-".length()));
115    }
116   
117    /**
118    * Moves the class field specified by the first parameter before the class field specified by the second parameter
119    *
120    * @param fieldToMove the class field to be moved
121    * @param beforeField the class field before which to insert the field being moved
122    */
 
123  1 toggle public void moveFieldBefore(String fieldToMove, String beforeField)
124    {
125  1 new ClassFieldEditPane(fieldToMove).dragTo(fieldsCanvas.findElement(By.id("field-" + beforeField)), 0, 0);
126    }
127   
128    /**
129    * Sets whether the class sheet should be updated or not.
130    *
131    * @param update {@code true} to update the class sheet, {@code false} otherwise
132    */
 
133  1 toggle public void setUpdateClassSheet(boolean update)
134    {
135  1 if (updateClassSheetCheckbox.isSelected() != update) {
136  1 updateClassSheetCheckbox.click();
137    }
138    }
139    }