Covert some code from javascript to Groovy script
Working code in Groovy
def handler = [(~/^Mac OS.*/) : { "open $it".execute() }, (~/^Windows.*/) : { "cmd /C start $it".execute() },
(~/.*/) : {
//--- Open chrome in desktop machine
def browsers =[ 'firefox'.'chrome' ]
//--- find a browser we know the location of
def browser = browsers.find {
"which $it".execute().waitFor() == 0
}
//--- and run it if one found
if( browser )
"$browser $it".execute()
}
]
def k = handler.find { k, v -> k.matcher( System.properties.'os.name' ).matches() }
k?.value( delegate )
}
"URL".browse()
Need to convert javascript to in groovy script
document.getElementById("username-field").value = "UserName";
document.getElementById("password-field").value = "Password";
document.getElementById("login_submit").click();
console.log(localStorage.getItem("access_token"));
MoreK ,
controlling the browser and the DOM inside via Groovy from ReadyAPI seems to me too difficult.
I would suggest doing the authentication directly within ReadyAPI (using OAuth or other authorization method which is in place), save the token and use it by your test steps.
Best regards,
Karel