1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui.browser; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.List; |
25 |
|
import java.util.regex.Pattern; |
26 |
|
|
27 |
|
import org.junit.internal.AssumptionViolatedException; |
28 |
|
import org.junit.rules.TestRule; |
29 |
|
import org.junit.runner.Description; |
30 |
|
import org.junit.runners.model.Statement; |
31 |
|
import org.openqa.selenium.Capabilities; |
32 |
|
import org.openqa.selenium.WebDriver; |
33 |
|
import org.openqa.selenium.remote.RemoteWebDriver; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@version |
54 |
|
@since |
55 |
|
|
|
|
| 92.3% |
Uncovered Elements: 2 (26) |
Complexity: 8 |
Complexity Density: 0.47 |
|
56 |
|
public class BrowserTestRule implements TestRule |
57 |
|
{ |
58 |
|
private String currentBrowserName; |
59 |
|
private String currentBrowserVersion; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
61 |
577 |
public BrowserTestRule(WebDriver driver)... |
62 |
|
{ |
63 |
577 |
Capabilities capability = ((RemoteWebDriver) driver).getCapabilities(); |
64 |
|
|
65 |
577 |
this.currentBrowserName = capability.getBrowserName(); |
66 |
|
|
67 |
577 |
this.currentBrowserVersion = capability.getVersion(); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
577 |
@Override... |
71 |
|
public Statement apply(final Statement base, final Description description) |
72 |
|
{ |
73 |
577 |
return new Statement() { |
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
74 |
577 |
@Override... |
75 |
|
public void evaluate() throws Throwable |
76 |
|
{ |
77 |
|
|
78 |
577 |
List<IgnoreBrowser> ignoredBrowsersList = new ArrayList<IgnoreBrowser>(); |
79 |
|
|
80 |
|
|
81 |
577 |
IgnoreBrowser ignoreBrowser = description.getAnnotation(IgnoreBrowser.class); |
82 |
577 |
if (ignoreBrowser != null) { |
83 |
29 |
ignoredBrowsersList.add(ignoreBrowser); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
577 |
IgnoreBrowsers ignoreBrowsers = description.getAnnotation(IgnoreBrowsers.class); |
88 |
577 |
if (ignoreBrowsers != null) { |
89 |
108 |
ignoredBrowsersList.addAll(Arrays.asList(ignoreBrowsers.value())); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
577 |
for (IgnoreBrowser ignoredBrowser : ignoredBrowsersList) { |
94 |
245 |
Pattern browserNamePattern = Pattern.compile(ignoredBrowser.value()); |
95 |
245 |
Pattern browserVersionPattern = Pattern.compile(ignoredBrowser.version()); |
96 |
|
|
97 |
245 |
if (browserNamePattern.matcher(currentBrowserName).matches() |
98 |
|
&& (ignoredBrowser.version().isEmpty() |
99 |
|
|| browserVersionPattern.matcher(currentBrowserVersion).matches())) |
100 |
|
{ |
101 |
0 |
throw new AssumptionViolatedException(ignoredBrowser.reason()); |
102 |
|
} |
103 |
|
} |
104 |
577 |
base.evaluate(); |
105 |
|
} |
106 |
|
}; |
107 |
|
} |
108 |
|
} |