System
OSX v10.13.4 / Elixir v1.6.5 / OTP 19 / Phoenix 1.3.2 / Wallaby 0.19.2 / PhantomJS 2.1
Issue
The following code works in testing
execute_script(session, "localStorage.setItem('test', 'foo'); return localStorage.getItem('test');")
However, if I call the exact same methods which are in a function called get_test()
inside app.js
of my Phoenix App
function get_test() {
localStorage.setItem('test', 'foo');
return localStorage.getItem('test');
}
window.get_test = get_test
And run the following in my test suite
execute_script(session, "return get_test();")
I get {:error, :obscured}
I have tried with selenium on the same code and it works. However, for some reason, with PhantomJS it does not seem to find functions that have been created by ourselves.
Am I missing something? I did notice in the tests for execute_script in wallaby there are no tests that call specifically created functions.
A similar test https://github.com/keathley/wallaby/blob/master/integration_test/cases/browser/local_storage_test.exs
of which I added the following to the local_storage_test
to verify I was not going nuts
@function_script """
function get_tester() {
localStorage.setItem('tester', 'foo');
return localStorage.getItem('tester');
}
return get_tester();
"""
session
|> visit("index.html")
|> execute_script(@function_script, fn(value) -> send self(), {:callback, value} end)
assert_received {:callback, "foo"}
and it passed. This is clearly something wrong with my app. Or Phantom config perhaps.
UPDATE:
Although not mentioned directly - I have narrowed this down to libsodim not loading properly with phantomjs. Back to basics on the debugging. Nothing wrong with the JS written. On a positive note, I now have a whole library of tests which is cool and some cool tools for testing.