How do you use Gatling's checkIf method? - gatling

Documented here, Gatling's checkIf method is intended for conditional checking. It's not available on ScenarioBuilder's fluent API but I can see it in the CheckSupport class. I have scoured the internet and cannot find a single example.
I'm using Gatling 2.3.1.

I found an example in their unit tests as follows:
http("untypedCheckIf").get("/")
.check(
checkIf("${bool}") {
jsonPath("$..foo")
}
)

Under Gatling 3.7.6, this worked for me:
http("Test Gatling checkIf()")
.get("/")
.check(status().in(200, 404).saveAs("httpStatus"))
.checkIf(session -> "200".equals(session.getString("httpStatus")))
.then(
jmesPath("someField")
.saveAs("fieldName"))
.checkIf(session -> "404".equals(session.getString("httpStatus")))
.then(
jmesPath("someField")
.withDefault("some default value")
.saveAs("fieldName"));

Related

Gatling script compilation error saying value 'check' is not a member

I have a method in a gatling user-script as below.
This script was written in gatling 2.3.
def registerAddress: ChainBuilder = {
exec(ws("WS Register Address").wsName(id)
.sendText(prefetchAddress)
.check(wsAwait.within(30).until(1).regex("success").exists))
.exec(ping)
}
I am converting this in to gatling 3.0 and when I try to run it I get the following error.
value check is not a member of io.gatling.http.action.ws.WsSendTextFrameBuilder
I searched everywhere but I couldn't find a documentation related to WsSendTextFrameBuilder class to change the method call accordingly.
Does anyone know a documentation related to this class or a way to fix this issue?
Thank you.
After going through the documentation of Gatling 2.3 and 3.0 I found the new calls for the above scenario.
Apparently the check method is not available anymore in the WsSendTextFrameBuilder class.
Instead of that should use the await method.
So the code would look something similar to below.
val checkReply = ws.checkTextMessage("request").check(regex("request-complete"))
def registerAddress: ChainBuilder = {
exec(ws("WS Register Address").wsName(id)
.sendText(prefetchAddress)
.await(30 seconds)(checkReply))
.exec(ping)
}

Cannot read property 'ARROW_DOWN' of undefined in protractor

I am using action sequences in protractor while running my spec i am facing this issue can anyone help why this is happening and how to solve it.
Below is my spec code:
describe("Actions demo", function(){
it(" Open website ",function(){
browser.get("http://posse.com/");
element(by.model("userInputQuery")).sendKeys("river");
browser.actions().mouseMove (element(by.model("locationQuery")))
.sendKeys("London").perform()
browser.actions.sendkeys(protractor.key.ARROW_DOWN);
browser.actions.sendkeys(protractor.key.ENTER).perform();
})
})
You should use protractor.Key.ARROW_DOWN instead of protractor.key.ARROW_DOWN.
You are using key with lowercase instead of Key with uppercase.
It should also be browser.actions().sendKeys(), actions() with parenthesis.
In addition to Silvan response, remember to use .perform() at the end every usage of .actions() otherwise it will not work.

How to reset fetch-mock for each test?

I have several React tests using Jest and fetch-mock, each one of them doing some get operations, so what I initially did was:
beforeAll(){
fetchMock.get(`*`, JSON.stringify(CORRECTRESPONSE));
}
However, in some tests I need to return wrong data as answer, something like:
test('Wrong get answer', ()=> {
fetchMock.get('*', JSON.stringify(WRONGRESPONSE), {overwriteRoutes: true});
}));
So, since I need to reset the response for the following tests (and so return CORRECTRESPONSE, I came up with this solution:
beforeEach(){
fetchMock.get(`*`, JSON.stringify(CORRECTRESPONSE));
}
afterEach(fetchMock.restore);
Is there anyway better to do this?
I don't understand why the previous answer (https://stackoverflow.com/a/49778196/689944) was set as correct. Cleanup up after tests by afterEach(fetchMock.restore) is a very good way.
That's also what is described in the fetch-mock documentation: http://www.wheresrhys.co.uk/fetch-mock/#api-lifecyclerestore_reset
According to the docs this should do it
beforeEach(() => {
fetch.resetMocks()
})

What is "buildQuery" parameter in "aor-graphql-client"

I am trying to work with "aor-graphql-client". When I try to create REST-client like in documentation, I get the error that "buildQueryFactory" is not a function.
As I see, this function is using in here.
From this object wee see that param "buildFactory" must be defined in options or in defaultOptions.
{
client: clientOptions,
introspection,
resolveIntrospection,
buildQuery: buildQueryFactory,
override = {},
...otherOptions
} = merge({}, defaultOptions, options);
In defaultOptions this parameter isn't defined. In my options I now define only {client: {uri: ...}}, and I don't know what buildQuery means.
The documentation you are referring to is from a deprecated package not related to aor-graphql-client (it was in fact our first try at GraphQL with Admin-on-rest).
The aor-graphql-client package only provides the basic "glue" to use GraphQL with Admin-on-rest.
The buildQuery option is explained here. In a nutshell, it is responsible for translating your GraphQL implementation to admin-on-rest.
We provided a sample implementation targeting the Graphcool backend: aor-graphql-client-graphcool. Use it as a starting point for implementing your own until we find some time to make the aor-graphql-client-simple (which will be a rewrite of the aor-simple-graphql-client you are referring to).
Have fun!
what is the buildfieldlist imported in builduery?

ReferenceError: printStackTrace is not defined

I get the following error "ReferenceError: printStackTrace is not defined",
when I tried to use StackTrace in my angular aplication.
stacktrace.js changed the API for v1.0.
You'll want to use
var callback = function(frames) { console.log(frames); };
var errback = function(err) { console.log(err.message); };
StackTrace.get().then(callback).catch(errback);
as suggested by the docs.
If all you want to do is parse an Error you can just use error-stack-parser
Please refer to the v0.x -> v1.x migration guide if you were using the old version.
By the way, if you need to use version 0.x you can find it in the stable branch on GitHub

Resources