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

File AbstractRegistrationPage.java

 

Coverage histogram

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

Code metrics

18
25
7
1
118
72
16
0.64
3.57
7
2.29

Classes

Class Line # Actions
AbstractRegistrationPage 37 25 0% 16 2
0.9696%
 

Contributing tests

This file is covered by 22 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.test.ui.po;
21   
22    import java.util.HashMap;
23    import java.util.List;
24    import java.util.Map;
25   
26    import org.openqa.selenium.By;
27    import org.openqa.selenium.WebElement;
28    import org.openqa.selenium.support.FindBy;
29   
30    /**
31    * Represents the actions possible for the different registration pages (standard registration page, lightbox
32    * registration page).
33    *
34    * @version $Id: 4621eb7f07691cf237e8ded065c03eaebdfa734b $
35    * @since 3.2M3
36    */
 
37    public abstract class AbstractRegistrationPage extends BasePage
38    {
39    @FindBy(id = "register")
40    private WebElement registerFormElement;
41   
42    private FormElement form;
43   
44    public abstract void clickRegister();
45   
 
46  21 toggle public void fillInJohnSmithValues()
47    {
48  21 fillRegisterForm("John", "Smith", "JohnSmith", "WeakPassword", "WeakPassword", "johnsmith@xwiki.org");
49    }
50   
 
51  41 toggle public void fillRegisterForm(final String firstName, final String lastName, final String username,
52    final String password, final String confirmPassword, final String email)
53    {
54  41 Map<String, String> map = new HashMap<String, String>();
55  41 if (firstName != null) {
56  24 map.put("register_first_name", firstName);
57    }
58  41 if (lastName != null) {
59  24 map.put("register_last_name", lastName);
60    }
61  41 if (username != null) {
62  29 map.put("xwikiname", username);
63    }
64  41 if (password != null) {
65  29 map.put("register_password", password);
66    }
67  41 if (confirmPassword != null) {
68  32 map.put("register2_password", confirmPassword);
69    }
70  41 if (email != null) {
71  24 map.put("register_email", email);
72    }
73  41 getForm().fillFieldsByName(map);
74    // There is a little piece of js which fills in the name for you.
75    // This causes flickering if what's filled in is not cleared.
76  41 if (username != null) {
77  29 while (!username.equals(getForm().getFieldValue(By.name("xwikiname")))) {
78  0 getForm().setFieldValue(By.name("xwikiname"), username);
79    }
80    }
81    }
82   
 
83  70 toggle private FormElement getForm()
84    {
85  70 if (this.form == null) {
86  23 this.form = new FormElement(this.registerFormElement);
87    }
88  70 return this.form;
89    }
90   
91    /** @return a list of WebElements representing validation failure messages. Use after calling register() */
 
92  16 toggle public List<WebElement> getValidationFailureMessages()
93    {
94  16 return getDriver().findElementsWithoutWaiting(By.xpath("//dd/span[@class='LV_validation_message LV_invalid']"));
95    }
96   
97    /** @return Is the specified message included in the list of validation failure messages. */
 
98  18 toggle public boolean validationFailureMessagesInclude(String message)
99    {
100  18 return getDriver().findElementsWithoutWaiting(
101    By.xpath("//dd/span[@class='LV_validation_message LV_invalid' and . = '" + message + "']")).size() > 0;
102    }
103   
104    /** Try to make LiveValidation validate the forms. */
 
105  12 toggle public void triggerLiveValidation()
106    {
107    // By manually invoking onsubmit with null as it's parameter,
108    // liveValidation will check fields but when it attempts to call submit with null as the
109    // input, it encounters an error which keeps the next page from loading.
110  12 getDriver().executeJavascript("try{ document.getElementById('register_first_name').focus(); " +
111    "document.getElementById('register').onsubmit(null); }catch(err){}");
112    }
113   
 
114  16 toggle public boolean isLiveValidationEnabled()
115    {
116  16 return !getDriver().findElementsWithoutWaiting(By.xpath("//div[@id='mainContentArea']/script")).isEmpty();
117    }
118    }