A header (Authorizathion) I set in the one scenario still exists when second scenario is ran.
I've looked through the documentation http://docs.behat.org/en/v3.0/ but I could find anything about my problem there.
Why is that ?
Use #insulated feature tag, this will start a clean browser for each scenario.
If this is not the issue use a method in #BeforeScenario hook where you can call reset/restart session methods.
Related
I have 2 testcases.
One test case, tests the authentication and gets token info in the header. I want to store it and use it in another testcase.
I tried store processor at 1st teastcase and tried retrieving it from 2nd testcase. But it says "couldnot find the key." Is this approach wrong?
Also, I tried queue /dequeue option. In this case i got,
Time out waiting for queue to return a result.
How to achieve this simple case?
Authentication should be mocked on all the other methods since you'll be testing the functionality and not the actual response from the server.
Take a look to this link:
https://docs.mulesoft.com/munit/2.2/mock-event-processor
I'm working on a project which uses middy and we have a custom middleware set up to validate auth tokens sent with Auth0. As part of this Auth0 makes an external request. I've been using Nock to mock these requests. What I'm finding is that if I test a function that is not wrapped in middy(), Nock works as expected and intercepts the request. However, if I try to test the function wrapped in middy() ( e.g. to ensure that all middlewares are being applied correctly ) then it fails. I've set up a very very basic example here. It just tests two functions, exactly the same, one wrapped and one not wrapped. Notice how as soon as the function is wrapped, something happens which causes Nock to not apply the interceptor correctly. I'm not sure if this is an issue with middy or Nock. I opened an issue with middy but have so far heard nothing.
Any help is greatly appreciated!
I'm not sure if this is your core issue or just in your example repo, but the reason your test fails in your repo is because you only tell Nock to mock one request and then make two separate attempts.
I can got the tests to pass by adding a call to persist, or twice, or skipping the first test, or creating a whole other Nock Interceptor.
READ THIS! - About interceptors
When you setup an interceptor for a URL and that interceptor is used, it is removed from the interceptor list. This means that you can intercept 2 or more calls to the same URL and return different things on each of them. It also means that you must setup one interceptor for each request you are going to have, otherwise nock will throw an error because that URL was not present in the interceptor list. If you don’t want interceptors to be removed as they are used, you can use the .persist() method.
If that doesn't solve a deeper problem for you, and you're having issues trying to determine why Nock is not matching a request, I recommend using the debug option.
We wanted to write some log(s) when there are failures, we observed karate.prevRequest works well within a feature file but returns null when we access prevRequest from a method in config object.
Is it expected? Is there a workaround to get the last request details?
In karate-config.js the value of karate is static, and maybe if you wrap it in a function(){} it may work. Else I would give this up, I really don't understand what is missing in the existing reports that you need to do all this. Are you testing or trying to create pretty reports :)
I'm trying to write some end to end tests for our application's login process, but am having trouble getting my head around the best way to set up the scenario where the user needs to change his password.
When our server responds to a successful login, a user object is returned with a changePassword field. The client then inspects the response and redirects accordingly.
My problem is getting the test set up so that the changePassword field is set - what is the best approach to use?
I see my options as:
Have a test set up and tear-down script for the server that creates a brand new user specifically for the test run with changePassword flag set in the database.
This seems like the most end to end approach, but is probably also the most effort & code.
Somehow intercept the http response in the test and modify the changePassword flag to be set for this test only.
Mock the http response completely. Using this approach is the most removed from an end to end test, but is perhaps the simplest?
Which is the best or most common approach? Also any general pointers on how to actually implement the above (particularly 1 and 2) with protractor would be great - I'm finding it hard to conceptually get straight in my head, and hence hard to know what to search for.
I'm using protractor as the test framework, with angular.js powering the client side, and a node server running utilising (among other things) express.js and mongoDB.
Having thought about this further, option 1 is the best solution, but is not always possible.
Option 2 is also possible, and option 3 should be avoided.
For option two, a mock module can be created like so: (coffeescript)
e2eInterceptors =->
angular.module('e2eInterceptors', [])
.factory('loginInterceptor', ()->
response: (response)->
# Only edit responses we are interested in
return response unless response.match(/login/)
# do the modifiations
response.data.changePassword = true
# return the response
return response
)
.config(($httpProvider)->
$httpProvider.interceptors.push('loginInterceptor')
)
You can then inject this module into your tests using
browser.addMockModule('e2eInterceptors', e2eInterceptors)
If you want to do this globally, you can put this in the onPrepare function in your protractor file, otherwise just call it when needed in tests.
I think your first approach is the most appropriate.
It would be useful anyway to test the new user creation, so it is not a waste.
And for example this example seems to be something similar: http://product.moveline.com/testing-angular-apps-end-to-end-with-protractor.html
I am using SoapUI with Groovy script and running into an issue when calling multiple APIs. In the system I am testing one WSDL/API handles the account registration, and returns an authenticator. I then use that returned authenticator to call a different WSDL/API and verify some information. I am able to call each of these WSDLs/APIs separate but when I put them together in a Groovy Script it doesn't work.
testRunner.runTestStepByName("RegisterUser");
testRunner.runTestStepByName("Property Transfer");
if(props.getPropertyValue("userCreated") == "success"){
testRunner.runTestStepByName("AuthenticateStoreUser");
To explain the first line will run the TestStep "RegisterUser". I then do a "Property Transfer" step which takes a few response values from "RegisterUser" - the first is "Status" to see if it succeeded or failed, second is the "Authenticator". I then do an if statement to check if "RegisterUser" succeeded then attempt to call "AuthenticateStoreUser". At this point everything looks fine. Though when it calls "AuthenticateStoreUser" it shows the thinking bar then fails like a timeout, and if I check the "raw" tab for the request it says
<missing xml data>.
Note, that if I try the "AuthenticateStoreUser" by itself the call works fine. It is only after calling "RegisterUser" in the Groovy Script that it behaves strange. I have tried this with a few different calls and believe it is an issue calling two different APIs.
Has anyone dealt with this scenario, or can provide further direction to what may be happening?
(I would have preferred to simply comment on the question, but I don't have enough rep yet)
Have you checked the Error log tab at the bottom when this occurs? If so, what does it say and is there a stacktrace you could share?