1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.qa.glnm.junit.seljup;
21
22 import static java.util.Collections.singletonList;
23
24 import java.util.List;
25
26 import org.junit.jupiter.api.extension.ExtensionContext;
27 import org.junit.jupiter.api.extension.ParameterContext;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import io.github.bonigarcia.seljup.BrowserBuilder;
32 import io.github.bonigarcia.seljup.BrowserType;
33 import io.github.bonigarcia.seljup.BrowsersTemplate.Browser;
34 import io.github.bonigarcia.seljup.SeleniumExtension;
35
36 final class SeleniumJupiterUtil {
37
38 private static final Logger LOG = LoggerFactory.getLogger(SeleniumJupiterUtil.class);
39 private static final SeleniumExtension SELENIUM_EXTENSION = new SeleniumExtension();
40
41 private SeleniumJupiterUtil() {
42
43 }
44
45 static List<Browser> asBrowserList(BrowserType type) {
46 BrowserBuilder builder;
47 switch (type) {
48 case EDGE:
49 if (LOG.isDebugEnabled()) {
50 LOG.debug("Using Edge.", type);
51 }
52 builder = BrowserBuilder.edge();
53 break;
54 case FIREFOX:
55 if (LOG.isDebugEnabled()) {
56 LOG.debug("Using Firefox.", type);
57 }
58 builder = BrowserBuilder.firefox();
59 break;
60 case CHROME:
61 if (LOG.isDebugEnabled()) {
62 LOG.debug("Using Chrome.", type);
63 }
64 builder = BrowserBuilder.chrome();
65 break;
66 default:
67 if (LOG.isInfoEnabled()) {
68 LOG.info("BrowserType {0} not supported. Using Chrome.", type);
69 }
70 builder = BrowserBuilder.chrome();
71 break;
72 }
73 Browser browser = builder.browserName(type.name()).version("LATEST").build();
74
75 return singletonList(browser);
76 }
77
78 static Object getDriverFromSelJup(ParameterContext driverParamContext, ExtensionContext context) {
79 if (getSeleniumExtension().supportsParameter(driverParamContext, context)) {
80 return getSeleniumExtension().resolveParameter(driverParamContext, context);
81 }
82 if (LOG.isInfoEnabled()) {
83 LOG.info("Selenium Jupiter Extension does not support driver parameter.");
84 }
85 return null;
86 }
87
88 static SeleniumExtension getSeleniumExtension() {
89 return SELENIUM_EXTENSION;
90 }
91
92 }