-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bdabf3
commit 78b2917
Showing
4 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.outr.robobrowser | ||
|
||
import org.openqa.selenium.{JavascriptExecutor, WebDriver} | ||
import scala.jdk.CollectionConverters._ | ||
|
||
case class WebStorageUtil(driver: WebDriver) { | ||
private val jsExecutor = driver.asInstanceOf[JavascriptExecutor] | ||
|
||
// Set an item in localStorage | ||
def setLocalStorageItem(key: String, value: String): Unit = { | ||
jsExecutor.executeScript(s"window.localStorage.setItem('$key','$value');") | ||
} | ||
|
||
// Get an item from localStorage | ||
def getLocalStorageItem(key: String): Option[String] = { | ||
Option(jsExecutor.executeScript(s"return window.localStorage.getItem('$key');").asInstanceOf[String]) | ||
} | ||
|
||
// Remove an item from localStorage | ||
def removeLocalStorageItem(key: String): Unit = { | ||
jsExecutor.executeScript(s"window.localStorage.removeItem('$key');") | ||
} | ||
|
||
// Clear all items from localStorage | ||
def clearLocalStorage(): Unit = { | ||
jsExecutor.executeScript("window.localStorage.clear();") | ||
} | ||
|
||
// Get all keys from localStorage | ||
def localStorageKeys: Set[String] = { | ||
val keys = jsExecutor.executeScript( | ||
"return Object.keys(window.localStorage);" | ||
).asInstanceOf[java.util.List[String]] | ||
keys.asScala.toSet | ||
} | ||
|
||
// Set an item in sessionStorage | ||
def setSessionStorageItem(key: String, value: String): Unit = { | ||
jsExecutor.executeScript(s"window.sessionStorage.setItem('$key','$value');") | ||
} | ||
|
||
// Get an item from sessionStorage | ||
def getSessionStorageItem(key: String): Option[String] = { | ||
Option(jsExecutor.executeScript(s"return window.sessionStorage.getItem('$key');").asInstanceOf[String]) | ||
} | ||
|
||
// Remove an item from sessionStorage | ||
def removeSessionStorageItem(key: String): Unit = { | ||
jsExecutor.executeScript(s"window.sessionStorage.removeItem('$key');") | ||
} | ||
|
||
// Clear all items from sessionStorage | ||
def clearSessionStorage(): Unit = { | ||
jsExecutor.executeScript("window.sessionStorage.clear();") | ||
} | ||
|
||
// Get all keys from sessionStorage | ||
def sessionStorageKeys: Set[String] = { | ||
val keys = jsExecutor.executeScript( | ||
"return Object.keys(window.sessionStorage);" | ||
).asInstanceOf[java.util.List[String]] | ||
keys.asScala.toSet | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters