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

File BaseElement.java

 

Coverage histogram

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

Code metrics

0
12
8
1
111
52
9
0.75
1.5
8
1.12

Classes

Class Line # Actions
BaseElement 37 12 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 239 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 org.openqa.selenium.By;
23    import org.openqa.selenium.WebDriverException;
24    import org.openqa.selenium.support.PageFactory;
25    import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
26    import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;
27    import org.xwiki.test.ui.PersistentTestContext;
28    import org.xwiki.test.ui.TestUtils;
29    import org.xwiki.test.ui.XWikiWebDriver;
30   
31    /**
32    * Represents all elements which include web pages as well as parts of web pages.
33    *
34    * @version $Id: 9a3045366538352d7da846b05b98c7ee969f1037 $
35    * @since 3.2M3
36    */
 
37    public class BaseElement
38    {
39    private static PersistentTestContext context;
40   
41    /** Used so that AllTests can set the persistent test context. */
 
42  32 toggle public static void setContext(PersistentTestContext context)
43    {
44  32 BaseElement.context = context;
45    }
46   
 
47  2465 toggle public BaseElement()
48    {
49  2465 ElementLocatorFactory finder = new AjaxElementLocatorFactory(getDriver(), getDriver().getTimeout());
50  2465 PageFactory.initElements(finder, this);
51    }
52   
 
53  12618 toggle protected XWikiWebDriver getDriver()
54    {
55  12618 return context.getDriver();
56    }
57   
58    /**
59    * @return Utility class with functions not specific to any test or element.
60    */
 
61  373 toggle protected static TestUtils getUtil()
62    {
63  373 return context.getUtil();
64    }
65   
66    /**
67    * @since 3.2M3
68    */
 
69  3 toggle public void waitForNotificationErrorMessage(String message)
70    {
71  3 waitForNotificationMessage("error", message);
72    }
73   
74    /**
75    * @since 3.2M3
76    */
 
77  1 toggle public void waitForNotificationWarningMessage(String message)
78    {
79  1 waitForNotificationMessage("warning", message);
80    }
81   
82    /**
83    * @since 3.2M3
84    */
 
85  57 toggle public void waitForNotificationSuccessMessage(String message)
86    {
87  57 waitForNotificationMessage("done", message);
88    }
89   
90    /**
91    * Waits for a notification message of the specified type with the given message to be displayed.
92    *
93    * @param level the notification type (one of error, warning, done)
94    * @param message the notification message
95    * @see 4.3
96    */
 
97  61 toggle private void waitForNotificationMessage(String level, String message)
98    {
99  61 By notificationMessageLocator =
100    By.xpath(String.format("//div[contains(@class,'xnotification-%s') and contains(., '%s')]", level, message));
101  61 getDriver().waitUntilElementIsVisible(notificationMessageLocator);
102    // In order to improve test speed, clicking on the notification will make it disappear. This also ensures that
103    // this method always waits for the last notification message of the specified level.
104  61 try {
105    // The notification message may disappear before we get to click on it.
106  61 getDriver().findElementWithoutWaiting(notificationMessageLocator).click();
107    } catch (WebDriverException e) {
108    // Ignore.
109    }
110    }
111    }