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

File XWikiWebDriver.java

 
testMail: Timed out after 10 seconds waiting for org.xwiki.test.ui....
testUploadImageAfterPreview: Timed out after 10 seconds waiting for org.xwiki.test.ui....
 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

16
173
86
1
888
587
108
0.62
2.01
86
1.26

Classes

Class Line # Actions
XWikiWebDriver 58 173 0% 108 62
0.7745454377.5%
 

Contributing tests

This file is covered by 575 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;
21   
22    import java.util.List;
23    import java.util.Set;
24    import java.util.concurrent.TimeUnit;
25    import java.util.logging.Level;
26   
27    import org.apache.commons.lang3.StringUtils;
28    import org.openqa.selenium.By;
29    import org.openqa.selenium.Capabilities;
30    import org.openqa.selenium.Keys;
31    import org.openqa.selenium.NoSuchElementException;
32    import org.openqa.selenium.NotFoundException;
33    import org.openqa.selenium.OutputType;
34    import org.openqa.selenium.StaleElementReferenceException;
35    import org.openqa.selenium.WebDriver;
36    import org.openqa.selenium.WebDriverException;
37    import org.openqa.selenium.WebElement;
38    import org.openqa.selenium.interactions.Keyboard;
39    import org.openqa.selenium.interactions.Mouse;
40    import org.openqa.selenium.remote.CommandExecutor;
41    import org.openqa.selenium.remote.ErrorHandler;
42    import org.openqa.selenium.remote.FileDetector;
43    import org.openqa.selenium.remote.RemoteStatus;
44    import org.openqa.selenium.remote.RemoteWebDriver;
45    import org.openqa.selenium.remote.SessionId;
46    import org.openqa.selenium.support.ui.ExpectedCondition;
47    import org.openqa.selenium.support.ui.Wait;
48    import org.openqa.selenium.support.ui.WebDriverWait;
49    import org.slf4j.Logger;
50    import org.slf4j.LoggerFactory;
51   
52    /**
53    * Wraps a {@link org.openqa.selenium.WebDriver} instance and adds new APIs useful for XWiki tests.
54    *
55    * @version $Id: 7bf9dcc5ed104091976e5b1e4fa9ab7856d7004b $
56    * @since 7.0M2
57    */
 
58    public class XWikiWebDriver extends RemoteWebDriver
59    {
60    private final static Logger LOGGER = LoggerFactory.getLogger(XWikiWebDriver.class);
61   
62    private RemoteWebDriver wrappedDriver;
63   
64    /**
65    * How long to wait (in seconds) before failing a test because an element cannot be found. Can be overridden with
66    * setTimeout.
67    */
68    private int timeout = 10;
69   
 
70  32 toggle public XWikiWebDriver(RemoteWebDriver wrappedDriver)
71    {
72  32 this.wrappedDriver = wrappedDriver;
73   
74    // Wait when trying to find elements till the timeout expires
75  32 setDriverImplicitWait();
76    }
77   
78    // XWiki-specific APIs
79   
 
80  4200 toggle public WebElement findElementWithoutWaiting(By by)
81    {
82    // Temporarily remove the implicit wait on the driver since we're doing our own waits...
83  4200 manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
84  4200 try {
85  4200 return this.wrappedDriver.findElement(by);
86    } finally {
87  4200 setDriverImplicitWait();
88    }
89    }
90   
 
91  332 toggle public List<WebElement> findElementsWithoutWaiting(By by)
92    {
93    // Temporarily remove the implicit wait on the driver since we're doing our own waits...
94  332 manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
95  332 try {
96  332 return this.wrappedDriver.findElements(by);
97    } finally {
98  332 setDriverImplicitWait();
99    }
100    }
101   
 
102  316 toggle public WebElement findElementWithoutWaiting(WebElement element, By by)
103    {
104    // Temporarily remove the implicit wait on the driver since we're doing our own waits...
105  316 manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
106  316 try {
107  316 return element.findElement(by);
108    } finally {
109  316 setDriverImplicitWait();
110    }
111    }
112   
 
113  556 toggle public List<WebElement> findElementsWithoutWaiting(WebElement element, By by)
114    {
115    // Temporarily remove the implicit wait on the driver since we're doing our own waits...
116  556 manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
117  556 try {
118  556 return element.findElements(by);
119    } finally {
120  556 setDriverImplicitWait();
121    }
122    }
123   
124    /**
125    * Should be used when the result is supposed to be true (otherwise you'll incur the timeout and an error will be
126    * raised!).
127    */
 
128  45 toggle public boolean hasElement(By by)
129    {
130  45 try {
131  45 findElement(by);
132  30 return true;
133    } catch (NoSuchElementException e) {
134  15 return false;
135    }
136    }
137   
 
138  3245 toggle public boolean hasElementWithoutWaiting(By by)
139    {
140  3245 try {
141  3245 findElementWithoutWaiting(by);
142  1425 return true;
143    } catch (NoSuchElementException e) {
144  1820 return false;
145    }
146    }
147   
 
148  9 toggle public boolean hasElementWithoutWaiting(WebElement element, By by)
149    {
150  9 try {
151  9 findElementWithoutWaiting(element, by);
152  4 return true;
153    } catch (NoSuchElementException e) {
154  5 return false;
155    }
156    }
157   
158    /**
159    * Should be used when the result is supposed to be true (otherwise you'll incur the timeout).
160    */
 
161  0 toggle public boolean hasElement(WebElement element, By by)
162    {
163  0 try {
164  0 element.findElement(by);
165  0 return true;
166    } catch (NoSuchElementException e) {
167  0 return false;
168    }
169    }
170   
 
171  5706 toggle public <T> void waitUntilCondition(ExpectedCondition<T> condition)
172    {
173    // Temporarily remove the implicit wait on the driver since we're doing our own waits...
174  5706 manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
175  5706 Wait<WebDriver> wait = new WebDriverWait(this, getTimeout());
176  5706 try {
177  5706 Test failure here wait.until(condition);
178    } finally {
179    // Reset timeout
180  5706 setDriverImplicitWait();
181    }
182    }
183   
184    /**
185    * Forces the driver to wait for a {@link #getTimeout()} number of seconds when looking up page elements
186    * before declaring that it cannot find them.
187    */
 
188  11142 toggle public void setDriverImplicitWait()
189    {
190  11142 setDriverImplicitWait(getTimeout());
191    }
192   
193    /**
194    * Forces the driver to wait for passed number of seconds when looking up page elements before declaring that it
195    * cannot find them.
196    */
 
197  11142 toggle public void setDriverImplicitWait(int timeout)
198    {
199  11142 manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);
200    }
201   
 
202  19685 toggle public int getTimeout()
203    {
204  19685 return this.timeout;
205    }
206   
207    /**
208    * @param timeout the number of seconds after which we consider the action to have failed
209    */
 
210  42 toggle public void setTimeout(int timeout)
211    {
212  42 this.timeout = timeout;
213    }
214   
215    /**
216    * Wait until the element given by the locator is displayed. Give up after timeout seconds.
217    *
218    * @param locator the locator for the element to look for.
219    */
 
220  1008 toggle public void waitUntilElementIsVisible(final By locator)
221    {
222  1008 waitUntilElementIsVisible(null, locator);
223    }
224   
225    /**
226    * Wait until the element specified by the locator is displayed. Give up after timeout seconds.
227    *
228    * @param parentElement where to look for the specified element, {@code null} to look everywhere
229    * @param locator the locator for the element to look for
230    * @since 7.2
231    */
 
232  1027 toggle public void waitUntilElementIsVisible(WebElement parentElement, final By locator)
233    {
234  1027 waitUntilElementsAreVisible(parentElement, new By[] {locator}, true);
235    }
236   
237    /**
238    * Wait until the element given by the locator is displayed. Give up after specified timeout (in seconds).
239    * <p>
240    * Only use this API if you absolutely need a longer timeout than the default, otherwise use
241    * {@link #waitUntilElementIsVisible(org.openqa.selenium.By)}.
242    *
243    * @param locator the locator for the element to look for
244    * @param timeout the timeout after which to give up
245    * @since 5.4RC1
246    */
 
247  5 toggle public void waitUntilElementIsVisible(final By locator, int timeout)
248    {
249  5 int currentTimeout = getTimeout();
250  5 try {
251  5 setTimeout(timeout);
252  5 waitUntilElementsAreVisible(new By[] {locator}, true);
253    } finally {
254  5 setTimeout(currentTimeout);
255    }
256    }
257   
258    /**
259    * Wait until one or all of an array of element locators are displayed.
260    *
261    * @param locators the array of element locators to look for
262    * @param all if true then don't return until all elements are found. Otherwise return after finding one
263    */
 
264  7 toggle public void waitUntilElementsAreVisible(final By[] locators, final boolean all)
265    {
266  7 waitUntilElementsAreVisible(null, locators, all);
267    }
268   
269    /**
270    * Wait until one or all of an array of element locators are displayed.
271    *
272    * @param parentElement where to look for the specified elements, {@code null} to look everywhere
273    * @param locators the array of element locators to look for
274    * @param all if true then don't return until all elements are found. Otherwise return after finding one
275    * @since 7.2
276    */
 
277  1034 toggle public void waitUntilElementsAreVisible(final WebElement parentElement, final By[] locators, final boolean all)
278    {
279  1034 waitUntilCondition(new ExpectedCondition<WebElement>()
280    {
 
281  1438 toggle @Override
282    public WebElement apply(WebDriver driver)
283    {
284  1438 WebElement element = null;
285  1438 for (By locator : locators) {
286  1439 try {
287  1439 if (parentElement != null) {
288    // Use the locator from the passed parent element.
289  24 element = parentElement.findElement(locator);
290    } else {
291    // Use the locator from the root.
292  1415 element = driver.findElement(locator);
293    }
294    } catch (NotFoundException e) {
295    // This exception is caught by WebDriverWait
296    // but it returns null which is not necessarily what we want.
297  264 if (all) {
298  263 return null;
299    }
300  1 continue;
301    }
302    // At this stage it's possible the element is no longer valid (for example if the DOM has
303    // changed). If it's no longer attached to the DOM then consider we haven't found the element
304    // yet.
305  1175 try {
306  1175 if (element.isDisplayed()) {
307  1032 if (!all) {
308  2 return element;
309    }
310  143 } else if (all) {
311  143 return null;
312    }
313    } catch (StaleElementReferenceException e) {
314    // Consider we haven't found the element yet
315  0 return null;
316    }
317    }
318  1030 return element;
319    }
320    });
321    }
322   
323    /**
324    * Waits until the given locator corresponds to either a hidden or a deleted element.
325    *
326    * @param locator the locator to wait for
327    */
 
328  165 toggle public void waitUntilElementDisappears(final By locator)
329    {
330  165 waitUntilElementDisappears(null, locator);
331    }
332   
333    /**
334    * Waits until the given locator corresponds to either a hidden or a deleted element.
335    *
336    * @param parentElement the element from which to start the search
337    * @param locator the locator to wait for
338    */
 
339  168 toggle public void waitUntilElementDisappears(final WebElement parentElement, final By locator)
340    {
341  168 waitUntilCondition(new ExpectedCondition<Boolean>()
342    {
 
343  208 toggle @Override
344    public Boolean apply(WebDriver driver)
345    {
346  208 try {
347  208 WebElement element = null;
348    // Note: Make sure to perform the find operation without waiting, since if the element is already
349    // gone (what we really want here) there is no point to wait for it.
350  208 if (parentElement != null) {
351    // Use the locator from the passed parent element.
352  3 element = findElementWithoutWaiting(parentElement, locator);
353    } else {
354    // Use the locator from the root.
355  205 element = findElementWithoutWaiting(locator);
356    }
357  50 return !element.isDisplayed();
358    } catch (NotFoundException e) {
359  158 return Boolean.TRUE;
360    } catch (StaleElementReferenceException e) {
361    // The element was removed from DOM in the meantime
362  0 return Boolean.TRUE;
363    }
364    }
365    });
366    }
367   
368    /**
369    * Shows hidden elements, as if they would be shown on hover. Currently implemented using JavaScript. Will throw a
370    * {@link RuntimeException} if the web driver does not support JavaScript or JavaScript is disabled.
371    *
372    * @param locator locator used to find the element, in case multiple elements are found, the first is used
373    */
 
374  3 toggle public void makeElementVisible(By locator)
375    {
376  3 makeElementVisible(findElement(locator));
377    }
378   
 
379  3 toggle public void makeElementVisible(WebElement element)
380    {
381    // RenderedWebElement.hover() don't seem to work, workarounded using JavaScript call
382  3 executeJavascript("arguments[0].style.visibility='visible'", element);
383    }
384   
385    /**
386    * Waits until the given element has a non-empty value for an attribute.
387    *
388    * @param locator the element to wait on
389    * @param attributeName the name of the attribute to check
390    */
 
391  3 toggle public void waitUntilElementHasNonEmptyAttributeValue(final By locator, final String attributeName)
392    {
393  3 waitUntilCondition(new ExpectedCondition<Boolean>()
394    {
 
395  3 toggle @Override
396    public Boolean apply(WebDriver driver)
397    {
398  3 try {
399  3 WebElement element = driver.findElement(locator);
400  3 return !element.getAttribute(attributeName).isEmpty();
401    } catch (NotFoundException e) {
402  0 return false;
403    } catch (StaleElementReferenceException e) {
404    // The element was removed from DOM in the meantime
405  0 return false;
406    }
407    }
408    });
409    }
410   
411    /**
412    * Waits until the given element has a certain value for an attribute.
413    *
414    * @param locator the element to wait on
415    * @param attributeName the name of the attribute to check
416    * @param expectedValue the attribute value to wait for
417    */
 
418  20 toggle public void waitUntilElementHasAttributeValue(final By locator, final String attributeName,
419    final String expectedValue)
420    {
421  20 waitUntilCondition(new ExpectedCondition<Boolean>()
422    {
 
423  33 toggle @Override
424    public Boolean apply(WebDriver driver)
425    {
426  33 try {
427  33 WebElement element = driver.findElement(locator);
428  33 return expectedValue.equals(element.getAttribute(attributeName));
429    } catch (NotFoundException e) {
430  0 return false;
431    } catch (StaleElementReferenceException e) {
432    // The element was removed from DOM in the meantime
433  0 return false;
434    }
435    }
436    });
437    }
438   
439    /**
440    * Waits until the given element ends with a certain value for an attribute.
441    *
442    * @param locator the element to wait on
443    * @param attributeName the name of the attribute to check
444    * @param expectedValue the attribute value to wait for
445    */
 
446  1 toggle public void waitUntilElementEndsWithAttributeValue(final By locator, final String attributeName,
447    final String expectedValue)
448    {
449  1 waitUntilCondition(new ExpectedCondition<Boolean>()
450    {
 
451  3 toggle @Override
452    public Boolean apply(WebDriver driver)
453    {
454  3 try {
455  3 WebElement element = driver.findElement(locator);
456  3 return element.getAttribute(attributeName).endsWith(expectedValue);
457    } catch (NotFoundException e) {
458  0 return false;
459    } catch (StaleElementReferenceException e) {
460    // The element was removed from DOM in the meantime
461  0 return false;
462    }
463    }
464    });
465    }
466   
467    /**
468    * Waits until the given element has a certain value as its inner text.
469    *
470    * @param locator the element to wait on
471    * @param expectedValue the content value to wait for
472    * @since 3.2M3
473    */
 
474  67 toggle public void waitUntilElementHasTextContent(final By locator, final String expectedValue)
475    {
476  67 waitUntilCondition(new ExpectedCondition<Boolean>()
477    {
 
478  67 toggle @Override
479    public Boolean apply(WebDriver driver)
480    {
481  67 WebElement element = driver.findElement(locator);
482  67 return Boolean.valueOf(expectedValue.equals(element.getText()));
483    }
484    });
485    }
486   
 
487  3538 toggle public Object executeJavascript(String javascript, Object... arguments)
488    {
489  3538 return executeScript(javascript, arguments);
490    }
491   
492    /**
493    * There is no easy support for alert/confirm window methods yet, see -
494    * http://code.google.com/p/selenium/issues/detail?id=27 -
495    * http://www.google.com/codesearch/p?hl=en#2tHw6m3DZzo/branches
496    * /merge/common/test/java/org/openqa/selenium/AlertsTest.java The aim is : <code>
497    * Alert alert = this.getDriver().switchTo().alert();
498    * alert.accept();
499    * </code> Until then, the following hack does override the confirm method in Javascript to return the given value.
500    *
501    * @param accept {@code true} to accept the confirmation dialog, {@code false} to cancel it
502    */
 
503  5 toggle public void makeConfirmDialogSilent(boolean accept)
504    {
505  5 String script = String.format("window.confirm = function() { return %s; }", accept);
506  5 executeScript(script);
507    }
508   
509    /**
510    * @see #makeConfirmDialogSilent(boolean)
511    * @since 3.2M3
512    */
 
513  0 toggle public void makeAlertDialogSilent()
514    {
515  0 executeScript("window.alert = function() { return true; }");
516    }
517   
518    /**
519    * Waits until the provided javascript expression returns {@code true}.
520    * <p>
521    * The wait is done while the expression returns {@code false}.
522    *
523    * @param booleanExpression the javascript expression to wait for to return {@code true}. The expression must have a
524    * {@code return} statement on the last line, e.g. {@code "return window.jQuery != null"}
525    * @param arguments any arguments passed to the javascript expression
526    * @throws IllegalArgumentException if the evaluated expression does not return a boolean result
527    * @see #executeJavascript(String, Object...)
528    * @since 6.2
529    */
 
530  2986 toggle public void waitUntilJavascriptCondition(final String booleanExpression, final Object... arguments)
531    throws IllegalArgumentException
532    {
533  2986 waitUntilCondition(new ExpectedCondition<Boolean>()
534    {
 
535  2986 toggle @Override
536    public Boolean apply(WebDriver driver)
537    {
538  2986 boolean result = false;
539   
540  2986 Object rawResult = executeJavascript(booleanExpression, arguments);
541  2986 if (rawResult instanceof Boolean) {
542  2986 result = (Boolean) rawResult;
543    } else {
544  0 throw new IllegalArgumentException("The executed javascript does not return a boolean value");
545    }
546   
547  2986 return result;
548    }
549    });
550    }
551   
552    // WebDriver APIs
553   
 
554  2941 toggle @Override
555    public void get(String s)
556    {
557  2941 this.wrappedDriver.get(s);
558    }
559   
 
560  1862 toggle @Override
561    public String getCurrentUrl()
562    {
563  1862 return this.wrappedDriver.getCurrentUrl();
564    }
565   
 
566  47 toggle @Override
567    public String getTitle()
568    {
569  47 return this.wrappedDriver.getTitle();
570    }
571   
 
572  398 toggle @Override
573    public List<WebElement> findElements(By by)
574    {
575  398 return this.wrappedDriver.findElements(by);
576    }
577   
 
578  13306 toggle @Override
579    public WebElement findElement(By by)
580    {
581  13306 return this.wrappedDriver.findElement(by);
582    }
583   
 
584  20 toggle @Override
585    public String getPageSource()
586    {
587  20 return this.wrappedDriver.getPageSource();
588    }
589   
 
590  0 toggle @Override
591    public void close()
592    {
593  0 this.wrappedDriver.close();
594    }
595   
 
596  32 toggle @Override
597    public void quit()
598    {
599  32 this.wrappedDriver.quit();
600    }
601   
 
602  0 toggle @Override
603    public Set<String> getWindowHandles()
604    {
605  0 return this.wrappedDriver.getWindowHandles();
606    }
607   
 
608  1372 toggle @Override
609    public String getWindowHandle()
610    {
611  1372 return this.wrappedDriver.getWindowHandle();
612    }
613   
 
614  2090 toggle @Override
615    public TargetLocator switchTo()
616    {
617  2090 return this.wrappedDriver.switchTo();
618    }
619   
 
620  30 toggle @Override
621    public Navigation navigate()
622    {
623  30 return this.wrappedDriver.navigate();
624    }
625   
 
626  22393 toggle @Override
627    public Options manage()
628    {
629  22393 return this.wrappedDriver.manage();
630    }
631   
632    // Remote WebDriver APIs
633   
 
634  0 toggle @Override
635    public void setFileDetector(FileDetector detector)
636    {
637  0 this.wrappedDriver.setFileDetector(detector);
638    }
639   
 
640  16 toggle @Override
641    public SessionId getSessionId()
642    {
643  16 return this.wrappedDriver.getSessionId();
644    }
645   
 
646  0 toggle @Override
647    public ErrorHandler getErrorHandler()
648    {
649  0 return this.wrappedDriver.getErrorHandler();
650    }
651   
 
652  0 toggle @Override
653    public void setErrorHandler(ErrorHandler handler)
654    {
655  0 this.wrappedDriver.setErrorHandler(handler);
656    }
657   
 
658  0 toggle @Override
659    public CommandExecutor getCommandExecutor()
660    {
661  0 return this.wrappedDriver.getCommandExecutor();
662    }
663   
 
664  926 toggle @Override
665    public Capabilities getCapabilities()
666    {
667  926 return this.wrappedDriver.getCapabilities();
668    }
669   
 
670  0 toggle @Override
671    public RemoteStatus getRemoteStatus()
672    {
673  0 return this.wrappedDriver.getRemoteStatus();
674    }
675   
 
676  10 toggle @Override
677    public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
678    {
679  10 return this.wrappedDriver.getScreenshotAs(outputType);
680    }
681   
 
682  5 toggle @Override
683    public WebElement findElementById(String using)
684    {
685  5 return this.wrappedDriver.findElementById(using);
686    }
687   
 
688  0 toggle @Override
689    public List<WebElement> findElementsById(String using)
690    {
691  0 return this.wrappedDriver.findElementsById(using);
692    }
693   
 
694  0 toggle @Override
695    public WebElement findElementByLinkText(String using)
696    {
697  0 return this.wrappedDriver.findElementByLinkText(using);
698    }
699   
 
700  0 toggle @Override
701    public List<WebElement> findElementsByLinkText(String using)
702    {
703  0 return this.wrappedDriver.findElementsByLinkText(using);
704    }
705   
 
706  0 toggle @Override
707    public WebElement findElementByPartialLinkText(String using)
708    {
709  0 return this.wrappedDriver.findElementByPartialLinkText(using);
710    }
711   
 
712  0 toggle @Override
713    public List<WebElement> findElementsByPartialLinkText(String using)
714    {
715  0 return this.wrappedDriver.findElementsByPartialLinkText(using);
716    }
717   
 
718  0 toggle @Override
719    public WebElement findElementByTagName(String using)
720    {
721  0 return this.wrappedDriver.findElementByTagName(using);
722    }
723   
 
724  0 toggle @Override
725    public List<WebElement> findElementsByTagName(String using)
726    {
727  0 return this.wrappedDriver.findElementsByTagName(using);
728    }
729   
 
730  0 toggle @Override
731    public WebElement findElementByName(String using)
732    {
733  0 return this.wrappedDriver.findElementByName(using);
734    }
735   
 
736  0 toggle @Override
737    public List<WebElement> findElementsByName(String using)
738    {
739  0 return this.wrappedDriver.findElementsByName(using);
740    }
741   
 
742  15 toggle @Override
743    public WebElement findElementByClassName(String using)
744    {
745  15 return this.wrappedDriver.findElementByClassName(using);
746    }
747   
 
748  2 toggle @Override
749    public List<WebElement> findElementsByClassName(String using)
750    {
751  2 return this.wrappedDriver.findElementsByClassName(using);
752    }
753   
 
754  0 toggle @Override
755    public WebElement findElementByCssSelector(String using)
756    {
757  0 return this.wrappedDriver.findElementByCssSelector(using);
758    }
759   
 
760  2 toggle @Override
761    public List<WebElement> findElementsByCssSelector(String using)
762    {
763  2 return this.wrappedDriver.findElementsByCssSelector(using);
764    }
765   
 
766  59 toggle @Override
767    public WebElement findElementByXPath(String using)
768    {
769  59 return this.wrappedDriver.findElementByXPath(using);
770    }
771   
 
772  0 toggle @Override
773    public List<WebElement> findElementsByXPath(String using)
774    {
775  0 return this.wrappedDriver.findElementsByXPath(using);
776    }
777   
 
778  9861 toggle @Override
779    public Object executeScript(String script, Object... args)
780    {
781  9861 return this.wrappedDriver.executeScript(script, args);
782    }
783   
 
784  0 toggle @Override
785    public Object executeAsyncScript(String script, Object... args)
786    {
787  0 return this.wrappedDriver.executeAsyncScript(script, args);
788    }
789   
 
790  0 toggle @Override
791    public void setLogLevel(Level level)
792    {
793  0 this.wrappedDriver.setLogLevel(level);
794    }
795   
 
796  698 toggle @Override
797    public Keyboard getKeyboard()
798    {
799  698 return this.wrappedDriver.getKeyboard();
800    }
801   
 
802  698 toggle @Override
803    public Mouse getMouse()
804    {
805  698 return this.wrappedDriver.getMouse();
806    }
807   
 
808  0 toggle @Override
809    public FileDetector getFileDetector()
810    {
811  0 return this.wrappedDriver.getFileDetector();
812    }
813   
 
814  0 toggle @Override
815    public String toString()
816    {
817  0 return this.wrappedDriver.toString();
818    }
819   
820    /**
821    * Compared to using clear() + sendKeys(), this method ensures that an "input" event is triggered on the JavaScript
822    * side for an empty ("") value. Without this, the clear() method triggers just a "change" event.
823    *
824    * @param textInputElement an element accepting text input
825    * @param newTextValue the new text value to set
826    * @see <a href="https://code.google.com/p/selenium/issues/detail?id=214">Issue 214</a>
827    * @since 7.2M3
828    */
 
829  74 toggle public void setTextInputValue(WebElement textInputElement, String newTextValue)
830    {
831  74 if (StringUtils.isEmpty(newTextValue)) {
832    // Workaround for the fact that clear() fires the "change" event but not the "input" event and javascript
833    // listening to the "input" event will not be executed otherwise.
834    // Note 1: We're not using CTRL+A and the Delete because the key combination to select the full input
835    // depends on the OS (on Mac it's META+A for example).
836    // Note 2: Sending the END key didn't always work when I tested it on Mac (for some unknown reason)
837  4 textInputElement.click();
838  4 textInputElement.sendKeys(
839    StringUtils.repeat(Keys.ARROW_RIGHT.toString(), textInputElement.getAttribute("value").length()));
840  4 textInputElement.sendKeys(
841    StringUtils.repeat(Keys.BACK_SPACE.toString(), textInputElement.getAttribute("value").length()));
842    } else {
843  70 textInputElement.clear();
844  70 textInputElement.sendKeys(newTextValue);
845    }
846    }
847   
848    /**
849    * Adds a marker in the DOM of the browser that will only be available until we leave or reload the current page.
850    * <p>
851    * To be used mainly before {@link #waitUntilPageIsReloaded()}.
852    *
853    * @since 7.4M2
854    */
 
855  135 toggle public void addPageNotYetReloadedMarker()
856    {
857  135 StringBuilder markerJs = new StringBuilder();
858  135 markerJs.append("new function () {");
859  135 markerJs.append(" var marker = document.createElement('div');");
860  135 markerJs.append(" marker.style.display='none';");
861  135 markerJs.append(" marker.id='pageNotYetReloadedMarker';");
862  135 markerJs.append(" document.body.appendChild(marker);");
863  135 markerJs.append("}()");
864   
865  135 executeJavascript(markerJs.toString());
866    }
867   
868    /**
869    * Waits until the previously added marker is no longer found on the current page, signaling that the page has been
870    * changed or reloaded. Useful when the page loading is done by jJavaScript and Selenium can not help in telling us
871    * when we have left the old page.
872    * <p>
873    * To be used always after {@link #addPageNotYetReloadedMarker()}.
874    *
875    * @since 7.4M2
876    */
 
877  135 toggle public void waitUntilPageIsReloaded()
878    {
879  135 waitUntilCondition(new ExpectedCondition<Boolean>()
880    {
 
881  158 toggle @Override
882    public Boolean apply(WebDriver input)
883    {
884  158 return !hasElementWithoutWaiting(By.id("pageNotYetReloadedMarker"));
885    }
886    });
887    }
888    }