1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.test.ui

File PersistentTestContext.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

2
25
14
1
156
87
15
0.6
1.79
14
1.07

Classes

Class Line # Actions
PersistentTestContext 35 25 0% 15 5
0.878048887.8%
 

Contributing tests

This file is covered by 251 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: a19dbe283148a04d3224607e3d8474504a7c9662 $
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 List<XWikiExecutor> executors;
45   
46    private XWikiWebDriver driver;
47   
48    /** Utility methods which should be available to tests and to pages. */
49    private TestUtils util;
50   
51    private Map<String, Object> properties = new HashMap<String, Object>();
52   
53    /**
54    * Starts an XWiki instance if not already started.
55    */
 
56  0 toggle public PersistentTestContext() throws Exception
57    {
58  0 this(Arrays.asList(new XWikiExecutor(0)));
59    }
60   
61    /**
62    * Don't start an XWiki instance, instead use an existing started instance.
63    */
 
64  30 toggle public PersistentTestContext(List<XWikiExecutor> executors)
65    {
66  30 initialize(executors);
67    // Note: If you wish to make Selenium use your default Firefox profile (for example to use your installed
68    // extensions such as Firebug), simply uncomment the following line:
69    // System.setProperty("webdriver.firefox.profile", "default");
70  30 WebDriverFactory webDriverFactory = new WebDriverFactory();
71  30 setDriver(webDriverFactory.createWebDriver(BROWSER_NAME_SYSTEM_PROPERTY));
72    }
73   
 
74  3 toggle public PersistentTestContext(List<XWikiExecutor> executors, XWikiWebDriver driver)
75    {
76  3 initialize(executors);
77  3 this.driver = driver;
78    }
79   
 
80  33 toggle private void initialize(List<XWikiExecutor> executors)
81    {
82  33 this.executors = executors;
83   
84  33 this.util = new TestUtils();
85  33 this.util.setExecutors(executors);
86    }
87   
 
88  19 toggle public PersistentTestContext(PersistentTestContext toClone)
89    {
90  19 this.executors = toClone.executors;
91  19 this.util = toClone.util;
92  19 this.driver = toClone.driver;
93  19 this.properties.putAll(toClone.properties);
94    }
95   
 
96  30202 toggle public XWikiWebDriver getDriver()
97    {
98  30202 return this.driver;
99    }
100   
 
101  30 toggle public void setDriver(XWikiWebDriver driver)
102    {
103  30 this.driver = driver;
104    }
105   
 
106  0 toggle public List<XWikiExecutor> getExecutors()
107    {
108  0 return executors;
109    }
110   
111    /**
112    * @return Utility class with functions not specific to any test or element.
113    */
 
114  2694 toggle public TestUtils getUtil()
115    {
116  2694 return this.util;
117    }
118   
 
119  14 toggle public void start() throws Exception
120    {
121  14 for (XWikiExecutor executor : this.executors) {
122  14 executor.start();
123    }
124    }
125   
 
126  30 toggle public void shutdown() throws Exception
127    {
128  30 if (this.driver != null) {
129  30 this.driver.quit();
130    }
131  30 for (XWikiExecutor executor : this.executors) {
132  31 executor.stop();
133    }
134    }
135   
 
136  230 toggle public Map<String, Object> getProperties()
137    {
138  230 return this.properties;
139    }
140   
141    /**
142    * Get a clone of this context which cannot be stopped by calling shutdown. this is needed so that individual tests
143    * don't shutdown when AllTests are being run.
144    */
 
145  19 toggle public PersistentTestContext getUnstoppable()
146    {
147  19 return new PersistentTestContext(this)
148    {
 
149  87 toggle @Override
150    public void shutdown()
151    {
152    // Do nothing, that's why it's unstoppable.
153    }
154    };
155    }
156    }