1. Project Clover database Sat Feb 2 2019 06:45:20 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
13
9
1
120
56
10
0.77
1.44
9
1.11

Classes

Class Line # Actions
BaseElement 37 13 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 228 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: f93f6e462d8aec25215f26d22fc031eeb5f45dd7 $
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  33 toggle public static void setContext(PersistentTestContext context)
43    {
44  33 BaseElement.context = context;
45    }
46   
 
47  7554 toggle public BaseElement()
48    {
49  7554 ElementLocatorFactory finder = new AjaxElementLocatorFactory(getDriver(), getDriver().getTimeout());
50  7554 PageFactory.initElements(finder, this);
51    }
52   
 
53  24972 toggle protected XWikiWebDriver getDriver()
54    {
55  24972 return context.getDriver();
56    }
57   
58    /**
59    * @return Utility class with functions not specific to any test or element.
60    */
 
61  388 toggle protected static TestUtils getUtil()
62    {
63  388 return context.getUtil();
64    }
65   
66    /**
67    * @since 3.2M3
68    */
 
69  1 toggle public void waitForNotificationErrorMessage(String message)
70    {
71  1 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  103 toggle public void waitForNotificationSuccessMessage(String message)
86    {
87  103 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  105 toggle private void waitForNotificationMessage(String level, String message)
98    {
99  105 By notificationMessageLocator =
100    By.xpath(String.format("//div[contains(@class,'xnotification-%s') and contains(., '%s')]", level, message));
101  105 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  105 try {
105    // The notification message may disappear before we get to click on it.
106  105 getDriver().findElementWithoutWaiting(notificationMessageLocator).click();
107    } catch (WebDriverException e) {
108    // Ignore.
109    }
110    }
111   
112    /**
113    * @since 8.4.5
114    * @since 9.0RC1
115    */
 
116  13 toggle protected boolean isElementVisible(By by)
117    {
118  13 return getDriver().findElementWithoutWaiting(by).isDisplayed();
119    }
120    }