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

File WebDriverFactory.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

8
23
1
1
89
45
6
0.26
23
1
6

Classes

Class Line # Actions
WebDriverFactory 41 23 0% 6 18
0.437543.8%
 

Contributing tests

No tests hitting this source file were found.

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.io.IOException;
23   
24    import org.jboss.arquillian.phantom.resolver.ResolvingPhantomJSDriverService;
25    import org.openqa.selenium.Keys;
26    import org.openqa.selenium.WebDriver;
27    import org.openqa.selenium.chrome.ChromeDriver;
28    import org.openqa.selenium.firefox.FirefoxDriver;
29    import org.openqa.selenium.firefox.FirefoxProfile;
30    import org.openqa.selenium.ie.InternetExplorerDriver;
31    import org.openqa.selenium.phantomjs.PhantomJSDriver;
32    import org.openqa.selenium.remote.DesiredCapabilities;
33    import org.openqa.selenium.remote.RemoteWebDriver;
34   
35    /**
36    * Create specific {@link WebDriver} instances for various Browsers.
37    *
38    * @version $Id: be1b0f54a9ec9e1f099ecd52d8a12de9b982a81d $
39    * @since 3.5M1
40    */
 
41    public class WebDriverFactory
42    {
 
43  32 toggle public XWikiWebDriver createWebDriver(String browserName)
44    {
45  32 WebDriver driver;
46  32 if (browserName.startsWith("*firefox")) {
47    // Native events are disabled by default for Firefox on Linux as it may cause tests which open many windows
48    // in parallel to be unreliable. However, native events work quite well otherwise and are essential for some
49    // of the new actions of the Advanced User Interaction. We need native events to be enable especially for
50    // testing the WYSIWYG editor. See http://code.google.com/p/selenium/issues/detail?id=2331 .
51  32 FirefoxProfile profile = new FirefoxProfile();
52  32 profile.setEnableNativeEvents(true);
53    // Make sure Firefox doesn't upgrade automatically on CI agents.
54  32 profile.setPreference("app.update.auto", false);
55  32 profile.setPreference("app.update.enabled", false);
56  32 profile.setPreference("app.update.silent", false);
57  32 driver = new FirefoxDriver(profile);
58   
59    // Hide the Add-on bar (from the bottom of the window, with "WebDriver" written on the right) because it can
60    // prevent buttons or links from being clicked when they are beneath it and native events are used.
61    // See https://groups.google.com/forum/#!msg/selenium-users/gBozOynEjs8/XDxxQNmUSCsJ
62    // We need to load a page before sending the keys otherwise WebDriver throws ElementNotVisible exception.
63  32 driver.get("data:text/plain;charset=utf-8,XWiki");
64  32 driver.switchTo().activeElement().sendKeys(Keys.chord(Keys.CONTROL, "/"));
65  0 } else if (browserName.startsWith("*iexplore")) {
66  0 driver = new InternetExplorerDriver();
67  0 } else if (browserName.startsWith("*chrome")) {
68  0 driver = new ChromeDriver();
69  0 } else if (browserName.startsWith("*phantomjs")) {
70  0 DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
71  0 capabilities.setCapability("handlesAlerts", true);
72  0 try {
73  0 driver = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), capabilities);
74    } catch (IOException e) {
75  0 throw new RuntimeException(e);
76    }
77    } else {
78  0 throw new RuntimeException("Unsupported browser name [" + browserName + "]");
79    }
80   
81    // Maximize the browser window by default so that the page has a standard layout. Individual tests can resize
82    // the browser window if they want to test how the page layout adapts to limited space. This reduces the
83    // probability of a test failure caused by an unexpected layout (nested scroll bars, floating menu over links
84    // and buttons and so on).
85  32 driver.manage().window().maximize();
86   
87  32 return new XWikiWebDriver((RemoteWebDriver) driver);
88    }
89    }