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); } }
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; }
@Override public LocalStorage getLocalStorage() { return new JSLocalStorage(this.getDriverContext()); }
@Test public void updatesLocalStorageInitiallyUglyCode(){ // initially code for backbone // the spec is loosely interpreted by different frameworks // so this will not be generic // todos-[framework] String storage_namespace = "todos-" + todoMVCSite.getName(); LocalStorage storage = new Storage((JavascriptExecutor)driver); int initialSize = 0; String[] keys; try{ keys = storage.getItem(storage_namespace).split(","); initialSize = keys.length; }catch(NullPointerException e){ // the key might not exist } todoMVC.enterNewToDo("First Added Item"); keys = storage.getItem(storage_namespace).split(","); int newSize = keys.length; assertThat(newSize, greaterThan(initialSize)); boolean foundit = false; // has title keys = storage.getItem(storage_namespace).split(","); for(String key : keys){ String itemKey = storage_namespace + "-" + key; String item = storage.getItem(itemKey); // should really parse json if(item.contains("\"" + "First Added Item" + "\"")) foundit = true; } assertThat(foundit, is(true)); }
@Override public LocalStorage getLocalStorage() { return this.webStorage.getLocalStorage(); }