cancel
Showing results for 
Search instead for 
Did you mean: 

Automating Oauth2 token retrieval- 'Implicit Grant' method . Java script in auth manager failing

SOLVED
Highlighted
New Contributor

Automating Oauth2 token retrieval- 'Implicit Grant' method . Java script in auth manager failing

We are trying to automate the OAuth2 Azure token retrieval and we use Implicit grant method. 

 

In the java script to automate the login UI page , we dont have id's , had to use the Xpath, so replaced the ids with xpaths, used the findchildbyXpath method, a compilation error is thrown saying FindbychildXpath is not available, so tried importing the package, when done, it throws script missing ; error. It is not liking any import statements there. So, not sure what is missing. Could someone please throw some ideas ? I am following the documentation in SmartBear -

 

https://support.smartbear.com/readyapi/docs/requests/auth/types/oauth2/automate/sample.html

 

Also, followed the recommendations in the community discussion, 
https://community.smartbear.com/t5/SoapUI-Pro/how-to-automate-our-manual-Oauth2-0-process/td-p/18348...

 

This is the javascript i am using, 

 

import javax.xml.xpath.XPathExpression ;

// This function asks for permission to use OAuth. The user must be logged in to use it. Logging in is performed in the script below.
function consent() {
if (document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div/div')){
document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div/div').click();
}
}

// This function fills user password in when the user name is already known. It uses the project-level "pass" property.
function fillpwd() {
document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div[2]').value = 'xxxxxxx';
document.FindChildByXpath('//*[@id="idSIButton9"]').Click();
window.setInterval(consent, 100);
}

//Thread.Sleep(3000);
// This script checks what page is displayed and provides the appropriate data. It uses the project-level "user" and "pass" properties.
if (document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div/div') && document.getElementByXpath('//*[@id="loginHeader"]/div')) {
document.FindChildByXpath('//*[@id="tilesHolder"]/div[1]/div/div').value = 'xxxxxx';
document.FindChildByXpath('//*[@id="tilesHolder"]/div[1]/div/div/div/div[3]/div').click();
window.setTimeout(fillpwd, 100);
//Thread.Sleep(3500);
} else if (document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div[2]')) {
// Thread.Sleep(3500);
fillpwd();
} else if(document.FindChildByXpath('//*[@id="i0281"]/div/div/div[1]/div[3]/div/div/div')){
window.setInterval(consent, 100);
}

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Automating Oauth2 token retrieval- 'Implicit Grant' method . Java script in auth manager failing

Hi @ManRam2020,

 

The document object does not have the FindChildByXpath() method, and it cannot be added to it anyhow. 

Please try using the evaluate() method instead: https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate

 

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

2 REPLIES 2
Moderator

Re: Automating Oauth2 token retrieval- 'Implicit Grant' method . Java script in auth manager failing

Hi @ManRam2020,

 

The document object does not have the FindChildByXpath() method, and it cannot be added to it anyhow. 

Please try using the evaluate() method instead: https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate

 

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

New Contributor

Re: Automating Oauth2 token retrieval- 'Implicit Grant' method . Java script in auth manager failing

Thank you so much for the response on this , Natalie, i tried using  evaluate() method per your recommendation, it throws errors saying two arguments needs to be passed.

TypeError: Failed to execute 'evaluate' on 'Document': 2 arguments required, but only 1 present.Uncaught TypeError: Failed to execute 'evaluate' on 'Document': 2 arguments required, but only 1 present.Uncaught TypeError: Failed to execute 'evaluate' on 'Document': 2 arguments required, but only 1 present.Uncaught

 

Also, our UI is defaulted to go through IE, in the link shared, it says, evaluate method is not supported for IE.

Am i missing something ? I am pretty new to API automation. 

 

Thanks in advance.