| 40 | import com.microsoft.playwright.options.RequestOptions; |
| 41 | |
| 42 | public class DriverFactory { |
| 43 | |
| 44 | private static final ThreadLocal<Playwright> playwright = new ThreadLocal<Playwright>(); |
| 45 | private static final ThreadLocal<Browser> driver = new ThreadLocal<Browser>(); |
| 46 | private static final ThreadLocal<String> token = new ThreadLocal<String>(); |
| 47 | protected static final ThreadLocal<BrowserContext> context = new ThreadLocal<BrowserContext>(); |
| 48 | protected static final ThreadLocal<Page> page = new ThreadLocal<Page>(); |
| 49 | protected static final ThreadLocal<Page> secondPage = new ThreadLocal<Page>(); |
| 50 | protected static final ThreadLocal<FrameLocator> frameLocator = new ThreadLocal<FrameLocator>(); |
| 51 | |
| 52 | /** |
| 53 | * Launches the preferred browser in the head(less) mode. |
| 54 | * @param browser The accepted browsers are chrome, edge, firefox, safari (webkit) |
| 55 | * @param headless Send true if you like to run in headless mode else false |
| 56 | * @author TestLeaf |
| 57 | */ |
| 58 | |
| 59 | public void setDriver(String browser, boolean headless) { |
| 60 | System.setProperty("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "1"); |
| 61 | playwright.set(Playwright.create()); |
| 62 | |
| 63 | switch (browser) { |
| 64 | case "chrome": |
| 65 | driver.set(getPlaywright().chromium().launch( |
| 66 | new BrowserType.LaunchOptions().setChannel("chrome") |
| 67 | .setHeadless(headless) |
| 68 | .setSlowMo(ConfigurationManager.configuration().slowMotion()))); |
| 69 | break; |
| 70 | case "edge": |
| 71 | driver.set(getPlaywright().chromium().launch( |
| 72 | new BrowserType.LaunchOptions().setChannel("msedge") |
| 73 | .setHeadless(headless) |
| 74 | .setSlowMo(ConfigurationManager.configuration().slowMotion()))); |
| 75 | break; |
| 76 | case "firefox": |
| 77 | driver.set(getPlaywright().firefox().launch( |
| 78 | new BrowserType.LaunchOptions() |
| 79 | .setHeadless(headless) |
| 80 | .setSlowMo(ConfigurationManager.configuration().slowMotion()))); |
| 81 | case "safari": |
| 82 | driver.set(getPlaywright().webkit().launch( |
| 83 | new BrowserType.LaunchOptions() |
| 84 | .setHeadless(headless) |
| 85 | .setSlowMo(ConfigurationManager.configuration().slowMotion()))); |
| 86 | default: |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | // Login through API and set the OAuth Token |
| 91 | setOauthToken(); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | public void setOauthToken() { |
| 96 | |
| 97 | // API request |
| 98 | APIRequestContext request = getPlaywright().request().newContext(new APIRequest.NewContextOptions().setBaseURL(ConfigurationManager.configuration().oauthUrl())); |
| 99 |
nothing calls this directly
no outgoing calls
no test coverage detected