SOAP UI- Automation token retrieval process not working

时间秒杀一切 提交于 2020-01-06 19:58:28

问题


I have implemented the java script in the Automation window of SOAP UI in the Oauth Profile. But this is not working until user runs it manually. How to automatically call the script whenever my token will expired.

enter code here
function consent(){
document.getElementById('loginform').click();
}

if (document.getElementById('login')) {
document.getElementById('login').value = 'xxxx@xxx.com';
document.getElementById('password').value = 'xxxxx';
document.loginform.submit();
}

else if (document.getElementById('loginform')){
window.setInterval(content,100);
}

回答1:


Here is how it needs to be handled.

  1. Call the service to get the token token.
  2. The above response must also contains the expiry time in the headers, extract it and store in a property along with token
  3. Make a normal service call which requires valid token
    • before sending request, find the current time and compare it with the property stored in step 2
    • if current time is less than expiry time, use the same token
    • else repeat the same steps

Now, the question stand is how to run random code before actually running a test step?

You should be able to execute some extra code, which is need in this case, using setup, teardown scripts of test case, test suite, project etc. i.e.,

Allow me to explain with an example.

You are running a test case which has a step to invoke some service and it requires token.

Add the required code to evaluate whether a token is to be retrieved again or reuse the existing one. This should be part of setup script of the test case, so that always the code in setup script gets executed before running a test case. Remember that, your script will not be run if you run on test step of that test case, so make sure you run the test case.

Note:
But, it can't be done for a test step level at the moment using SoapUI open source edition.

There is feature called Events available in Ready! API, where one can have very fine control on what to be done and when. This feature is not available in Open Source edition of SoapUI.

But for open source, an extension available, which I did some time ago, where that will allow some one to run some custom code for certain events like beforeStep, afterStep etc., That is tried using Groovy Script. However, you seemed to be using Javascript here. If you wish you may give a try the extension, of course, if needed.

Update:

As author of question request for some info, so updating the answer.

You can have a look this documentation link which shows how to use the custom events functionality of pro software to do something more when certain conditions are met on demand.

Also there is a webinar by SmartBear team which shows how to use events, but little lengthy in time. All uses groovy.

I see you using Javascript, is there anything that driving you to use it? or just you comfortable using it? Never mind, you should be able to use it.



来源:https://stackoverflow.com/questions/35427172/soap-ui-automation-token-retrieval-process-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!