private void saveLocalStorage(String account) { WebDriver driver = util.getEngine().getDriver(); if(driver instanceof WebStorage) { WebStorage webStorage = (WebStorage) driver; LocalStorage localStorage = webStorage.getLocalStorage(); Properties pro = new Properties(); for(String key : localStorage.keySet()) { pro.setProperty(key, localStorage.getItem(key)); } PathUtil.proStore(pro, "localStorage." + account); } }
/** * 保存sessionStorage信息 * @param account */ private void saveSessionStorage(String account) { WebDriver driver = util.getEngine().getDriver(); if(driver instanceof WebStorage) { WebStorage webStorage = (WebStorage) driver; SessionStorage sessionStorage = webStorage.getSessionStorage(); Properties pro = new Properties(); for(String key : sessionStorage.keySet()) { pro.setProperty(key, sessionStorage.getItem(key)); } PathUtil.proStore(pro, "sessionStorage." + account); } }
/** * 加载sessionStorage信息 * @param accountNameValue * @return */ private boolean loadSessionStorage(String accountNameValue, Map<String, String> customMap) { WebDriver webDriver = util.getEngine().getDriver(); if(webDriver instanceof WebStorage) { WebStorage webStorage = (WebStorage) webDriver; SessionStorage sessionStorage = webStorage.getSessionStorage(); Properties pro = new Properties(); if(PathUtil.proLoad(pro, "sessionStorage." + accountNameValue)) { if(pro.isEmpty()) { return false; } pro.putAll(customMap); pro.stringPropertyNames().parallelStream().forEach((key) -> { sessionStorage.setItem(key, pro.getProperty(key)); }); return true; } } return false; }
private boolean loadLocalStorage(String accountNameValue, Map<String, String> customMap) { WebDriver webDriver = util.getEngine().getDriver(); if(webDriver instanceof WebStorage) { WebStorage webStorage = (WebStorage) webDriver; LocalStorage localStorage = webStorage.getLocalStorage(); Properties pro = new Properties(); if(PathUtil.proLoad(pro, "localStorage." + accountNameValue)) { if(pro.isEmpty()) { return false; } pro.putAll(customMap); pro.stringPropertyNames().parallelStream().forEach((key) -> { localStorage.setItem(key, pro.getProperty(key)); }); return true; } } return false; }
private DesiredCapabilities getDescription(WebDriver instance, Capabilities capabilities) { DesiredCapabilities caps = new DesiredCapabilities(capabilities.asMap()); caps.setJavascriptEnabled(instance instanceof JavascriptExecutor); if (instance instanceof TakesScreenshot) { caps.setCapability(CapabilityType.TAKES_SCREENSHOT, true); } if (instance instanceof LocationContext) { caps.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true); } if (instance instanceof ApplicationCache) { caps.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true); } if (instance instanceof NetworkConnection) { caps.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, true); } if (instance instanceof WebStorage) { caps.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true); } if (instance instanceof FindsByCssSelector) { caps.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true); } if (instance instanceof Rotatable) { caps.setCapability(CapabilityType.ROTATABLE, true); } if (instance instanceof HasTouchScreen) { caps.setCapability(CapabilityType.HAS_TOUCHSCREEN, true); } return caps; }
public static WebStorage storage( WebDriver driver ) { return null; }
static WebStorage getWebStorage(WebDriver driver) { return convert(driver, WebStorage.class, CapabilityType.SUPPORTS_WEB_STORAGE, RemoteWebStorage.class); }