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/183485
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);
}
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