private void checkThatProxyIsEnabled(Config config) { if (!config.proxyEnabled() && config.fileDownload() == PROXY) { throw new IllegalStateException("config.proxyEnabled == false but config.fileDownload == PROXY. " + "You need to enable proxy server automatically."); } }
private boolean passBasicAuthThroughUrl(Config config, AuthenticationType authenticationType, String domain, String login, String password) { return hasAuthentication(domain, login, password) && !config.proxyEnabled() && authenticationType == AuthenticationType.BASIC; }
private void beforeNavigateTo(Config config, SelenideProxyServer selenideProxy, AuthenticationType authenticationType, String domain, String login, String password) { if (config.proxyEnabled()) { checkThatProxyIsStarted(selenideProxy); beforeNavigateToWithProxy(selenideProxy, authenticationType, domain, login, password); } else { beforeNavigateToWithoutProxy(authenticationType, domain, login, password); } }
public Result createDriver(Config config, WebDriverFactory factory, Proxy userProvidedProxy, List<WebDriverEventListener> listeners) { if (!config.reopenBrowserOnFail()) { throw new IllegalStateException("No webdriver is bound to current thread: " + currentThread().getId() + ", and cannot create a new webdriver because reopenBrowserOnFail=false"); } SelenideProxyServer selenideProxyServer = null; Proxy browserProxy = userProvidedProxy; if (config.proxyEnabled()) { selenideProxyServer = new SelenideProxyServer(config, userProvidedProxy); selenideProxyServer.start(); browserProxy = selenideProxyServer.createSeleniumProxy(); } WebDriver webdriver = factory.createWebDriver(config, browserProxy); log.info("Create webdriver in current thread " + currentThread().getId() + ": " + webdriver.getClass().getSimpleName() + " -> " + webdriver); WebDriver webDriver = addListeners(webdriver, listeners); return new Result(webDriver, selenideProxyServer); }
@Override public File execute(SelenideElement proxy, WebElementSource linkWithHref, Object[] args) throws IOException { WebElement link = linkWithHref.findAndAssertElementIsInteractable(); Config config = linkWithHref.driver().config(); long timeout = getTimeout(config, args); if (config.fileDownload() == HTTPGET) { LOG.config("selenide.fileDownload = " + System.getProperty("selenide.fileDownload") + " download file via http get"); return downloadFileWithHttpRequest.download(linkWithHref.driver(), link, timeout); } if (!config.proxyEnabled()) { throw new IllegalStateException("Cannot download file: proxy server is not enabled. Setup proxyEnabled"); } if (linkWithHref.driver().getProxy() == null) { throw new IllegalStateException("Cannot download file: proxy server is not started"); } return downloadFileWithProxyServer.download(linkWithHref, link, linkWithHref.driver().getProxy(), timeout); }