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

File PersistentTestContext.java

 

Coverage histogram

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

Code metrics

0
17
11
1
138
70
11
0.65
1.55
11
1

Classes

Class Line # Actions
PersistentTestContext 35 17 0% 11 2
0.928571492.9%
 

Contributing tests

This file is covered by 567 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.Arrays;
23    import java.util.HashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import org.xwiki.test.integration.XWikiExecutor;
28   
29    /**
30    * This is a container for holding all of the information which should persist throughout all of the tests.
31    *
32    * @version $Id: bb7d732f02169a91ed00213a8201dfd1769e100e $
33    * @since 3.2M3
34    */
 
35    public class PersistentTestContext
36    {
37    /**
38    * Decide on which browser to run the tests and defaults to Firefox if no system property is defined (useful for
39    * running in your IDE for example).
40    */
41    private static final String BROWSER_NAME_SYSTEM_PROPERTY = System.getProperty("browser", "*firefox");
42   
43    /** This starts and stops the wiki engine. */
44    private final List<XWikiExecutor> executors;
45   
46    private final XWikiWebDriver driver;
47   
48    /** Utility methods which should be available to tests and to pages. */
49    private final TestUtils util = new TestUtils();
50   
51    private WebDriverFactory webDriverFactory = new WebDriverFactory();
52   
53    private final Map<String, Object> properties = new HashMap<String, Object>();
54   
55    /**
56    * Starts an XWiki instance if not already started.
57    */
 
58  17 toggle public PersistentTestContext() throws Exception
59    {
60  17 this(Arrays.asList(new XWikiExecutor(0)));
61    }
62   
63    /**
64    * Don't start an XWiki instance, instead use an existing started instance.
65    */
 
66  32 toggle public PersistentTestContext(List<XWikiExecutor> executors) throws Exception
67    {
68  32 this.executors = executors;
69   
70  32 this.util.setExecutors(executors);
71   
72    // Note: If you wish to make Selenium use your default Firefox profile (for example to use your installed
73    // extensions such as Firebug), simply uncomment the following line:
74    // System.setProperty("webdriver.firefox.profile", "default");
75  32 this.driver = this.webDriverFactory.createWebDriver(BROWSER_NAME_SYSTEM_PROPERTY);
76    }
77   
 
78  15 toggle public PersistentTestContext(PersistentTestContext toClone)
79    {
80  15 this.executors = toClone.executors;
81  15 this.driver = toClone.driver;
82  15 this.properties.putAll(toClone.properties);
83    }
84   
 
85  27019 toggle public XWikiWebDriver getDriver()
86    {
87  27019 return this.driver;
88    }
89   
 
90  0 toggle public List<XWikiExecutor> getExecutors()
91    {
92  0 return executors;
93    }
94   
95    /**
96    * @return Utility class with functions not specific to any test or element.
97    */
 
98  3076 toggle public TestUtils getUtil()
99    {
100  3076 return this.util;
101    }
102   
 
103  17 toggle public void start() throws Exception
104    {
105  17 for (XWikiExecutor executor : this.executors) {
106  17 executor.start();
107    }
108    }
109   
 
110  32 toggle public void shutdown() throws Exception
111    {
112  32 this.driver.quit();
113  32 for (XWikiExecutor executor : this.executors) {
114  32 executor.stop();
115    }
116    }
117   
 
118  215 toggle public Map<String, Object> getProperties()
119    {
120  215 return this.properties;
121    }
122   
123    /**
124    * Get a clone of this context which cannot be stopped by calling shutdown. this is needed so that individual tests
125    * don't shutdown when AllTests are being run.
126    */
 
127  15 toggle public PersistentTestContext getUnstoppable()
128    {
129  15 return new PersistentTestContext(this)
130    {
 
131  97 toggle @Override
132    public void shutdown()
133    {
134    // Do nothing, that's why it's unstoppable.
135    }
136    };
137    }
138    }