Selenium: How do I inject a Javascript variable across my tests?

I don't think it is possible out of box. Workaround should work - add to the page some library that can deserialize from JSON (e.g. Dojo), use it to load an array definition to some JavaScript variable and before leaving page get it back, storing it out of scope request. But I must say you have a kind of strange request - what are trying to do?

I'm trying to convert Selenium HTML tests that use the Selenium global JS variable "storedVars" to store global information. Sadly, this is not available using the WebDriverBackedSelenium driver. Thanks for your reply, but I don't understand your response.

Please provide an example that sets and retrieves a global variable using "getEval". Thanks, - – Dave Aug 24 '11 at 14:54 I use the WebDriver directly for some time, so I'll provide ony this "pseudocode": String arrayJson = ""; selenium. GetEval("window.document.

StoredVars = "+ arrayJson) // do some work ... // arrayJson = selenium. GetEval("window.dojo. ToJson(window.document.

StoredVars)") – binary_runner Aug 24 '11 at 23:49 If you navigate away from the page you're testing, does "window.document. StoredVars" still retain its value? It's not for me, and that is the problem.

I'm looking for a JS variable that will persist across different pages. – Dave Aug 30 '11 at 12:58 You have to read it and store the value outside request scope. JS variable cannot survive page reload - you can use cookies for that but thats's hardly an improvement and I do not know if Selenium handles them right.

– binary_runner Aug 30 '11 at 16:04.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions