Forum Discussion
I'm not a coder so i can't help with your groovy, but i wanted to confirm some points to rule out any issues with the SQL.
Your SQL is:
SELECT mycodes
FROM secured.myaccesscodes ac
JOIN
secured.mytable us
ON
ac.myid = us.myid
WHERE us.username = "'+myuser+'"
AND ac.activeflag = 1
Some RDBMSs struggle if you use partial aliasing. You've aliased everything but the initial column you are retrieving in your result set, so rather than 'select mycodes from', instead use 'select ac.mycodes from'.
Secondly i just wanted to ensure your notation is correct relative to the FROM and JOIN clauses.
Your FROM/JOIN clauses read
'FROM secured.myaccesscodes ac JOIN secured.mytable us'
Can you confirm 'secured' is the database name, so 'myaccesscodes' and 'mytable' are the table names? I struggled before using an earlier version of SoapUI (not ReadyAPI!) when i included the database name in the table identifier in my SQL. Once i removed the database name reference so my table identifiers included only the table, my SQL worked fine, but didn't when i included the databasename.
Cheers, sorry i can't comment on anything else,
Rich
- Rmuenks16 years agoOccasional Contributor
Thanks for the feedback regarding SQL, but this code works in a Groovy script.
What I need help with is understanding in what ways the script editor inside the OAuth 2 profile GUI differs from the capabilities of a script inside a Groovy script. Also, if there is a limitation on what you can do within the OAuth 2 automation profile scripting, what options exist for making a SQL database call from within the automation profile to get our unique 6-digit security token during OAuth 2 automation profile to validate the user?
When running the code in the original post in the OAuth2 automation scripts GUI I get an error that says:
ReferenceError: Can't find variable: Sql]
if I use an "import Groovy.sql.Sql" at the beginning I get an error that says:
Error: syntax error (scriptToValidate#1)
So, it seems like the "Automation scripts for OAuther 2 profile" screen has some limitations on what sort of code can execute within it, but I'm not finding anything in the documentation, or online, to indicate that limitation.
Thanks again!
- nmrao6 years agoChampion Level 3
Would you please provide the following?
1. Screen shot showing groovy script test along with script (fully visible). Also appreciate if you can attach the full script in text mode which will quickly help try.
2. Assuming that you are using MS SQL Server. What driver / library files available under ReadyAPI?
3. Full stacktrace of the error.
- Rmuenks16 years agoOccasional Contributor
Hi,
So when I press "get the token" it opens up our login pages, so I created 'automation' scripts to handle those login screens. Page 1 is the Enter User Name screen. Page 2, the Enter Password screen, Page 3, the Request authentication code screen, and Page 4, the Enter authentication code screen.
What I'm trying to do is make a database call from within the automation script which goes to our database and gets the authentication token, rather than trying to get it from our emails, or text messages, which I would imagine is even harder to code into the automation script. But the SQL calls I'm making in the script shown below work fine if I pull them out into a separate Groovy script, just not inside the Oath2 automation script. So I'm curious why it's not working. After I get the authorization code from the database I intended on putting that in the field on the screen and pressing submit.
Thank you,
Roy
Page 1
if (document.getElementById('txtUserName')) {
document.getElementById('txtUserName').value = '${#Project#Prop_UserName}';
document.getElementById('btnNext').click();
}
Page 2
if (document.getElementById('txtPassword')) {
document.getElementById('txtPassword').value = '${#Project#Prop_Password}';
document.getElementById('btnSignin').click();
}
Page 3
if (document.getElementById('MainContent_rblDeliveryMethods_0')) {
document.getElementById('MainContent_rblDeliveryMethods_0').click();
document.getElementById('btnRequestCode').click();
}
Page 4
if (document.getElementById('MainContent_AccessCodeRequiredFieldValidator')) {
MyDBServer = "<removed for security reasons>";
MyUser = "<removed for security reasons>";
Mysql = sql.newInstance('jdbc:sqlserver://' + MyDBServer + ':1433;databaseName=<removed for security reasons>;integratedSecurity=true','','','com.microsoft.sqlserver.jdbc.SQLServerDriver');
Mydata = Mysql.firstRow("SELECT AC.AccessCode FROM UserAccessCodes AC JOIN Users US ON AC.UserID = US.UserID Where US.UserName = '"+MyUser+"' and AC.ActiveFlag = 1");
AuthCode = Mydata;
Mysql.close();
document.getElementById('MainContent_AccessCodeRequiredFieldValidator').value = AuthCode;
document.getElementById('btnConfirmCode').click();
}
- Olga_T6 years agoSmartBear Alumni (Retired)
Hi all,
Thank you, richie, for your reply.
Rmuenks1, let me refer to some of our Community leaders, maybe they will be able to assist.
groovyguy , avidCoder , nmrao , HimanshuTayal, could you please have a look at the issue? Do you have any ideas or suggestions?
Community, feel free to post your comments!
Thanks everyone in advance!