I need to pass variable(Extracted from response) from one Request to other Requests in the same Thread Group.
Response of first Thread:
42[
"createGameRsp",
{
"response": {
"title": "Create Successful",
"result": "Testo60 was successfully created. \n GameID: 56 \n Password: ",
"error": "",
"game": "texas",
"gameID": 56
}
}
]
Another thread:
42[
"get_joingame",
{
"uid": "Esdv7CHkwo1ATMfvY6NcWBTM5YB4d3nj",
"key": "AUEEW891WL",
"socketId":"${sid}",
"username":${userName}",
"avatar": "avatar17.jpg",
"language": "en",
"playerMove": "",
"joinGame": "",
"replay": 0,
"gameID":"${__property(GlobalGameID)}",
"gameNo": 0,
"data": "&seat=${counter2}&buyin=500&privateTable=2&clubId=0",
"players": 0,
"level": 347,
"lastAction": "ep.playNow",
"game": "texas",
"playMoney": 1,
"role": "1",
"playerId":"${playerId}",
"displayName": "p10",
"seat":"${counter2}"
}
]
I've used beanshell assertion to set variable in to jmeter property
${__set.Property(GlobalGameID,$(gameID))};
While executing i'm getting
Assertion error:true
Assertion failure:false
Assertion failure message:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``${__set.Property(GlobalGameID,$(gameID))};'' : Attempt to access property on undefined variable or class name
enter image description here
First of all you have an error in your function syntax
You need to remove the dot between set and Property
JMeter Variables are referenced in form ${variable-name}
${__setProperty(GlobalGameID,${gameID},)}
Use Function Helper Dialog to generate proper function syntax
Second, it's not recommended to inline JMeter Functions or Variables into Beanshell scripts, you can use props and vars shorthands instead:
props.put("GlobalGameID", vars.get("gameID"));
Third, it's not recommended to use Beanshell for scripting, if you need you should use JSR223 Test Elements and Groovy language as Groovy provides maximum performance comparing to other scripting engines
More information: Using JMeter Variables With Multiple Thread Groups
Related
I want to use response assertion to match the response from server, here when I am getting responses it shows like {
"per_page": 6,
"total": 12,
"data": [
{
"last_name": "Lawson",
"id": 7,
"avatar": "https://reqres.in/img/faces/7-image.jpg",
"first_name": "Michael",
"email": "michael.lawson#reqres.in"
},
But in response assertion it showing like
Assertion failure message:Test failed: text expected to contain /{
"per_page": 6,
"total": 12,
"data": [
{
"last_name": "Lawson",
"id": 7,
"avatar": "https://reqres.in/img/faces/7-image.jpg",
"first_name": "Michael",
"email": "michael.lawson#reqres.in"
},
{
and therefor it gets failing even though its matching but due to addition / (slash), its getting failed.
JMeter doesn't "add" slashes anywhere, it's just a matter of visualization, you're getting your pattern surrounded with slashes as there is a mismatch, basically JMeter fails to find what you put in the "Patterns to test" in the application response
Demo:
See lines 472 and 480 in the ResponseAssertion source
So make sure that your response contains the pattern and be aware that every line brake or empty space matters so if your server returns non-formatted string and you're expecting a "pretty" one - the assertion will fail.
We cannot suggest the best option without seeing you actual response, however full-text comparing 2 JSON entities doesn't seem a good approach to me in terms of robustness and reliability, you might want to consider JSON Assertion or JSON JMESPath Assertion instead
I have JSON request as following:
{
"type": "SIGNUP",
"data": {
"userAccountInfo": {
"email": "ta0620050706#gmail.com",
"password": "qweQwe123!"
},
"userAddressInfo": {
"country": "United States"
},
"userPersonalInfo": {
"firstName": "test",
"lastName": "test"
}
}
}
How can extract ta0620050706#gmail.com from the following request, considering the value of the email is always dinamic?
Any help is appreciated!
If you're talking about HTTP Request sampler and the above JSON is in the "Body Data" tab like:
You can extract the email by adding a JSR223 PreProcessor and using the following code there:
vars.put('email', new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue()).data.userAccountInfo.email)
It will extract the value you're looking for and store it into ${email} JMeter Variable
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
I just installed the latest version of Selenium Runner
npm install -g selenium-side-runner
on my Mac High Sierra. I'm running node v14.1.0. I'm using Chrome Driver v 83. I want to run a very simple file that simply opens a page, waiting for an element on that page to be present. However, I'm getting a "NoSuchSessionError: This driver instance does not have a valid session ID" error.
The Selenium Runner .side file in question is
$ cat selenium/KarmaDecayGetResults.side
{
"id": "9664bd47-b18f-405f-9bd3-06014919ca7e",
"version": "2.0",
"name": "KarmaDecay",
"url": "http://karmadecay.com",
"tests": [
{
"id": "8f462171-01b8-4247-87b9-40e2d1fef143",
"name": "KarmaDecay",
"commands": [
{
"id": "c297319b-4350-4f04-b72e-1a347a67100c",
"comment": "",
"command": "open",
"target": "/r/gifs/comments/gz5v5j/caracal_visits_jimmy_kimmel_gets_shy_and_tries_to/",
"targets": [],
"value": ""
},
{
"id": "32f35ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "pause",
"target": "",
"targets": [],
"value": "2000"
},
{
"id": "95261633-22ff-4477-ab6f-7b3354bea8b9",
"comment": "",
"command": "setWindowSize",
"target": "1440x900",
"targets": [],
"value": ""
},
{
"id": "fbf35ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "waitForElementPresent",
"target": "id=content",
"targets": [],
"value": ""
},
{
"id": "aed35ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "waitForElementVisible",
"target": "id=content",
"targets": [],
"value": ""
},
{
"id": "fbf59ed7-1a28-4540-a93d-3cb8ba0e012a",
"comment": "",
"command": "pause",
"target": "",
"targets": [],
"value": "2000"
}
]
}
],
"suites": [
{
"id": "91809d77-24c1-457b-8266-516b2fc58555",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": [
"8f462171-01b8-4247-87b9-40e2d1fef143"
]
}
],
"urls": [
"http://karmadecay.com/"
],
"plugins": []
}
Below is the output of running the file ...
$ PATH=/Users/davea/Documents/workspace/article_project/selenium/dev:/usr/local/bin:$PATH /usr/local/bin/selenium-side-runner -c "goog:chromeOptions.args=[--headless,--nogpu] browserName=chrome" selenium/KarmaDecayGetResults.side
FAIL ./DefaultSuite.test.js (301.959s)
Default Suite
✕ KarmaDecay (300540ms)
● Default Suite › KarmaDecay
: Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error:
8 | jest.setTimeout(300000);
9 | describe("Default Suite", () => {
> 10 | it("KarmaDecay", async () => {
| ^
11 | await tests["KarmaDecay"](driver, vars);
12 | expect(true).toBeTruthy();
13 | });
at new Spec (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
at Suite.<anonymous> (DefaultSuite.test.js:10:3)
● Default Suite › KarmaDecay
NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
at ../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/webdriver.js:729:38
at Object.thenFinally [as finally] (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/promise.js:124:12)
at runMicrotasks (<anonymous>)
at WebdriverEnvironment.global.cleanup (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-environment-selenium/dist/index.js:30:7)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 302.159s
Ran all test suites.
Do I need to be doing something different to get my test to run cleanly?
invalid session id
The invalid session ID error is a WebDriver error that occurs when the server does not recognize the unique session identifier. This happens if the session has been deleted or if the session ID is invalid.
A WebDriver session can be deleted through either of the following ways:
Explicit session deletion: A WebDriver session is explicitly deleted when explicitly invoking the quit() method.
Implicit session deletion: A WebDriver session is implicitly deleted when you close the last window or tab invoking close().
You can find a detailed discussion in selenium.common.exceptions.WebDriverException: Message: invalid session id using Selenium with ChromeDriver and Chrome through Python
This usecase
I don't see any such error within your code block. However your main error seems to be...
Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error:
...which implies that the Async callback being referred to in the error is getting timedout even with timeout set as 300000:
jest.setTimeout(300000);
The real issue is with the url of KarmaDecay which contains a hCaptcha to keep off automated bots.
URL Snapshot:
Conclusion
As per your test setup to execute the selenium-side-runner within the website http://karmadecay.com/ first you have to interact with the captcha to get authenticated and then run your tests.
You can find a couple of relevant discussions on how to interact with recaptcha in:
How to identify the 32 bit data-sitekey of ReCaptcha V2 to obtain a valid response programmatically using Selenium and Python Requests?
Find the reCAPTCHA element and click on it — Python + Selenium
How to click on the reCaptcha using Selenium and Java
Another aspect
If the initial tests works fine but for the rest of your tests you get a session ID error most possibly the Selenium WebDriver controled Browsing Context is getting detected and hence blocking the next requests.
There are different reasons for the WebDriver controled Web Browser to get detected and simultaneously get blocked. You can find a couple of detailed discussion in:
Can a website detect when you are using selenium with chromedriver?
Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection
I'm trying to create a "Global OptionSet"-attribute (sd_MyAttribute) for an existing entity (entity ID = 70816501-edb9-4740-a16c-6a5efbc05d84) via Dynamics CRM WebAPI.
The JSON I send is this using method "POST":
{
"#odata.type": "Microsoft.Dynamics.CRM.PicklistAttributeMetadata",
"OptionSet": {
"#odata.type": "Microsoft.Dynamics.CRM.OptionSetMetadata",
"IsGlobal": true,
"Name": "sd_MyPickList",
"OptionSetType": "Picklist",
"MetadataId": "a50cfc0a-e206-ea11-a811-000d3ab82e70"
},
"AttributeType": "Picklist",
"SchemaName": "sd_MyAttribute",
"Description": {
"#odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"#odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "This is the attribute I want to create.",
"LanguageCode": 1033
}
]
},
"DisplayName": {
"#odata.type": "Microsoft.Dynamics.CRM.Label",
"LocalizedLabels": [
{
"#odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
"Label": "This is the attribute I want to create.",
"LanguageCode": 1033
}
]
},
"RequiredLevel": {
"Value": "None",
"CanBeChanged": true
}
}
I expected to get a status 204 response, indicating that a new Picklist attribute on the entity using the sd_MyPickList option set has been created.
Unfortunately, the response is:
{
"error": {
"code": "0x80048403",
"message": "Only Local option set can be created through the attribute create. IsGlobal flag must be set to 'false'.",
"innererror": {
"message": "Only Local option set can be created through the attribute create. IsGlobal flag must be set to 'false'.",
"type": "Microsoft.Crm.CrmException",
"stacktrace": " ...)"
}
}
}
There is already an issue in the github project (see https://github.com/MicrosoftDocs/dynamics-365-customer-engagement/issues/601), but I wonder whether there is a way around this problem - what json do I need to send to create an attribute adressing a global option set? Is there someone who has successfully created such an entity attribute via web-api?
There is a usecase, I don't have the ability to use an existing library for that and importing a solution is not an option in my case.
Would be perfect if someone can provide a simple json that can be send e.g. using the Contact entity and any global optionset.
Finally, I found a way to accomplish what I need. To specify the global option set I need to use the "#odata.bind" action in the JSON data. For an attribute "sd_MyAttribute" that uses the global OptionSet with the MetaDataId "62654906-7A0b-ea11-a817-000d3ab826fd", I need to do POST:
{
"#odata.type": "Microsoft.Dynamics.CRM.PicklistAttributeMetadata",
"GlobalOptionSet#odata.bind": "/GlobalOptionSetDefinitions(62654906-7A0b-ea11-a817-000d3ab826fd)",
"AttributeType": "Picklist",
"SchemaName": "sd_MyAttribute",
"Description": { ... },
"DisplayName": { ... },
"RequiredLevel": { ... }
}
If the entity does have the MetaDataId "70916b01-edb2-4840-a16b-6a2efbc75d84", the URI for the POST would be "/api/data/v9.0/EntityDefinitions(70916b01-edb2-4840-a16b-6a2efbc75d84)/Attributes" (logical- or schema-names are not supported).
Hope my question and answer does help someone who gets the same error message.
I'm trying to extract coverage data from our SonarQube instance using the 'api/measures/component' endpoint. This is for a multi module java project. Using POSTMAN i can query for a single java file using a 'componentKey' which is build up of string like this
[maven-groupId]:[maven-artifactId]:[path to java file]
which generates a string like
com.i.pc.e.components.o:om-wf-e:src/main/java/com/i/e/o/wf/actions/Xxxx.java
and returns this json response
{
"component": {
"id": "AVci_6G7elHqFlTqG_OC",
"key": "com.i.pc.e.components.o:om-wfl-e:src/main/java/com/i/e/o/wf/actions/Xxxx.java",
"name": "Xxxx.java",
"qualifier": "FIL",
"path": "src/main/java/com/i/e/om/wf/actions/Xxxxx.java",
"language": "java",
"measures": []
},
"metrics": [
{
"key": "coverage",
"name": "Coverage",
"description": "Coverage by unit tests",
"domain": "Coverage",
"type": "PERCENT",
"higherValuesAreBetter": true,
"qualitative": true,
"hidden": false,
"custom": false,
"decimalScale": 1,
"bestValue": "100.0",
"worstValue": "0.0"
}
]
}
This is fine for a one-off request but I need to do this for a number of Java source files and I won't have the Maven details to hand.
Is there a convention or documentation on the format of the 'componentKey'?
Ideally i'd like to define the full package and java source file name in the 'compomentKey' or is there a way to look up the 'componentId' via some other REST API call?
Use the components service to iterate through your tree (or sub-trees within your tree) starting from your project and feeding your sonar.projectKey value into the baseComponentKey parameter. Pay particular attention to the strategy parameter, which determines what sub-set of children a call retrieves.
Once you have the data on each child, it should be simple to iterate through them to get their measures.