org.openqa.selenium.html5.WebStorage Java Examples

The following examples show how to use org.openqa.selenium.html5.WebStorage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoModuleProxy.java    From phoenix.webui.framework with Apache License 2.0 6 votes vote down vote up
/**
 * 保存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);
    }
}
 
Example #2
Source File: AutoModuleProxy.java    From phoenix.webui.framework with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #3
Source File: DefaultSession.java    From selenium with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> 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 Rotatable) {
    caps.setCapability(CapabilityType.ROTATABLE, true);
  }
  if (instance instanceof HasTouchScreen) {
    caps.setCapability(CapabilityType.HAS_TOUCHSCREEN, true);
  }
  return caps.asMap();
}
 
Example #4
Source File: UtilsTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void providesRemoteAccessToWebStorage() {
  DesiredCapabilities caps = new DesiredCapabilities();
  caps.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true);

  CapableDriver driver = mock(CapableDriver.class);
  when(driver.getCapabilities()).thenReturn(caps);

  WebStorage storage = Utils.getWebStorage(driver);

  LocalStorage localStorage = storage.getLocalStorage();
  SessionStorage sessionStorage = storage.getSessionStorage();

  localStorage.setItem("foo", "bar");
  sessionStorage.setItem("bim", "baz");

  verify(driver).execute(DriverCommand.SET_LOCAL_STORAGE_ITEM, ImmutableMap.of(
      "key", "foo", "value", "bar"));
  verify(driver).execute(DriverCommand.SET_SESSION_STORAGE_ITEM, ImmutableMap.of(
      "key", "bim", "value", "baz"));
}
 
Example #5
Source File: AutoModuleProxy.java    From phoenix.webui.framework with Apache License 2.0 5 votes vote down vote up
/**
 * 加载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;
}
 
Example #6
Source File: AutoModuleProxy.java    From phoenix.webui.framework with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: CurrentWebDriver.java    From webtau with Apache License 2.0 4 votes vote down vote up
@Override
public LocalStorage getLocalStorage() {
    return ((WebStorage)getDriver()).getLocalStorage();
}
 
Example #8
Source File: CurrentWebDriver.java    From webtau with Apache License 2.0 4 votes vote down vote up
@Override
public SessionStorage getSessionStorage() {
    return ((WebStorage)getDriver()).getSessionStorage();
}
 
Example #9
Source File: LocalStorage.java    From webtau with Apache License 2.0 4 votes vote down vote up
private org.openqa.selenium.html5.LocalStorage getLocalStorage() {
    WebStorage webStorage = (WebStorage) driver;
    return webStorage.getLocalStorage();
}
 
Example #10
Source File: AddWebStorage.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public Class<WebStorage> getDescribedInterface() {
  return WebStorage.class;
}
 
Example #11
Source File: AddWebStorage.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public WebStorage getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
  return new RemoteWebStorage(executeMethod);
}
 
Example #12
Source File: Utils.java    From selenium with Apache License 2.0 4 votes vote down vote up
static WebStorage getWebStorage(WebDriver driver) {
  return convert(driver, WebStorage.class, CapabilityType.SUPPORTS_WEB_STORAGE,
      RemoteWebStorage.class);
}