IJavaScriptExecutor js = driver as IJavaScriptExecutor;
String script = "localStorage.setItem('webApiUrl', 'http://localhost:49240/api/');";
js.ExecuteScript(script);
...
Message: Test method MyApp.SeliniumUITest.UnitTest1.TestMethod1 threw exception:System.InvalidOperationException: (UnexpectedJavaScriptError).
public class UnitTest1
{
//FirefoxDriver firefox;
IWebDriver driver = new FirefoxDriver();
// This is the test to be carried out...
[TestMethod]
public void TestMethod1()
{
// Write webApiUrl=""http://localhost:49240/api/"" to local storage
//IWebDriver jdriver; // assume assigned elsewhere
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
String script = "localStorage.setItem('webApiUrl', 'http://localhost:49240/api/');";
js.ExecuteScript(script);
//firefox = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:52276/login");
// Implicit wait until Element is present...
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
// Explicit wait...
//WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
//IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
//{
// return d.FindElement(By.Id("login-name"));
//});
// Login...
driver.FindElement(By.Id("login-name")).Clear();
driver.FindElement(By.Id("login-name")).SendKeys("adm");
//driver.FindElement(By.Id("login-password")).Clear();
//driver.FindElement(By.Id("password")).SendKeys("");
driver.FindElement(By.Id("login-button")).Click();
}
// This closes the driver down after the test has finished.
[TestCleanup]
public void TearDown()
{
driver.Quit();
}
}
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("window.localStorage.setItem('webApiUrl', 'http://localhost:49240/api/');");
Someone please let me know if this could be streamlined or if there may be any pitfalls!
Thanks All!
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/538e6249-c044-4338-9d66-5cfcc726af6b%40googlegroups.com.--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/DmPyAMPyy44/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
IWebDriver driver = new FirefoxDriver();
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
...
--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/DmPyAMPyy44/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/d4195ae5-69a2-4bb6-913f-43cc6917890a%40googlegroups.com.
"{"loginName":"alittle","...1485589cda0df41a2e39c"}" When I log out, the value is displayed in local storage as ... """" That's four double quotes.
I just need to make sure it has the longer string after login and whatever the value is displayed above when logged out. When I double click on the logged out value displayed I see escaped quotes as follows - "\"\"". I guess I'll play around with that a bit. |
--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/DmPyAMPyy44/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c036e1fb-0556-4fe0-9a5e-509f1e999b76%40googlegroups.com.
String storageValue = (String)js.ExecuteScript("return localStorage.getItem('ngStorage-userInfo')");
Now the problem is this... I think I'm running up against a timing issue of some sort. I leave the browser open on my test so I can check local storage when the login page is once again displayed. I'm getting the full login screen in the code while local storage shows """" in the browser.
Everything seems to work properly in my Login test where I use the following code...
driver.FindElement(By.Id("user-dropdown"));
// Check local storage for login token
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
String storageValue = (String)js.ExecuteScript("return localStorage.getItem('ngStorage-userInfo')");
// Assert that the local storage value is not empty (contains login token information)...
Assert.AreNotEqual("\"\"", storageValue);
I wonder why I'm not seeing the same timing like scenario as I see in the Logout test. ? I don't want to use Thread.sleep method of doing things. I would have hoped that the local storage would have been cleared before the user name element on the login screen was displayed.
...
--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/DmPyAMPyy44/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/083ca489-255c-48bd-ab71-6fbbde0547c8%40googlegroups.com.