Covert some code from javascript to Groovy script
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"));
Solved! Go to Solution.
- Labels:
-
Function Tests
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@MoreK ,
it would help if you describe your case more in detail.
Do you want to populate a form in the browser from ReadyAPI Groovy script?
Best regards,
Karel
https://apimate.eu
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Karel,
Yes.
As in my case I have to take access token from UI, because of that I want to open application with credentials and then that generated token is store in localStorage of application and get that token from DOM.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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
https://apimate.eu
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have tried but still not use
Token is not fetch by using OAuth as that login site is 3 party application which dynamical changes
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@MoreK ,
it's harder to do the authorization in ReadyAPI in case of proprietary methods, but you can capture the HTTP requests in your browser (e.g. Ctrl+Shift+I in Chrome) and do the same in ReadyAPI.
For dynamic parts you can use properties. This may need some effort, but for longer term it pays off.
Best regards,
Karel
https://apimate.eu
