This question already has answers here:
Karate Gatling - exclude specific request or feature from report [duplicate]
(2 answers)
Closed 1 year ago.
Data from the feeder are not passing in the feature. How should I pass data from feeder to feature? I will describe my code here:
Simulation
val protocol: KarateProtocol = karateProtocol(
"/" -> Nil,
"/" -> pauseFor("get" -> 3, "post" -> 5)
)
private val feeder = Iterator.continually(Map(
"uri" -> s"https://$runEnv-url.com",
"token" -> getApiAuthToken(userLogin, userPassword, userAccount).getToken,
"userId" -> getApiAuthToken(userLogin, userPassword, userAccount).getUserID
))
val scn: ScenarioBuilder =
scenario("Scenario name")
.feed(feeder)
.exec(session => {
println(session)
session
})
.exec(karateFeature("classpath:specs/api.feature"))
setUp(
scn.inject(constantUsersPerSec(1) during(1 seconds)).protocols(protocol)
)
Feature:
Feature: Scenario name
Background:
* url __gatling.uri
* header Authentication = 'Token ' + __gatling.token
Scenario: Get User Details
Given path 'users', __gatling.userId
When method get
Then status 200
And print response
And as result, I'm getting undefined instead of data from the feeder.
Logs:
When method get
http call failed after 92 milliseconds for url: /users
UPD: code from answer works, but get value from session still returns undefined
Use karateSet() (new in 1.1.0) as shown in this example
Something like this should work in your Scala simulation:
.feed(feeder)
.exec(karateSet("token", session => session("token").as[String]))
Please read the docs also: https://github.com/intuit/karate/tree/master/karate-gatling#chaining
And if still stuck, follow this process please: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
Related
Hi I want to store the value return by below code in JMeter webDriver Sampler . but i am getting error.
String access_token = WDS.browser.executeScript("return window.localStorage.getItem(localStorage.key(2))");
WDS.log.info("access_token : " + access_token);
OR
var access_token = WDS.browser.executeScript("return window.localStorage.getItem(localStorage.key(2))");
WDS.log.info("access_token : " + access_token);
Both above ways are not working?
In order to be able to help we need to know the details of the error "you are getting". Also it's unclear what localStorage.key(2) object stands for.
Here is an example of getting se:fkey value from https://stackoverflow.com website:
I used default language for WebDriver Sampler: javascript and the following piece of code:
WDS.sampleResult.sampleStart()
WDS.browser.get('https://stackoverflow.com')
var access_token = WDS.browser.executeScript('return window.localStorage.getItem("se:fkey")')
WDS.log.info('Got the following value from local storage: ' + access_token)
WDS.sampleResult.sampleEnd()
And it works just fine:
If you additionally need to store the value into a JMeter Variable add the following line:
WDS.vars.put('access_token', access_token)
and you will be able to access the extracted value as ${access_token} where required.
More information: The WebDriver Sampler: Your Top 10 Questions Answered
I'm trying to write some Ruby code to update GitLab CI/CD variables using the REST endpoint update variable. When I perform a curl with the same path, the same private token, and the same --form data it updates the variable as expected. When I use the Ruby code that I put together based on reading stackoverflow and the net::http docs, it fails with a 404 URL not found.
I can use a similar piece of code to create a new CI/CD variable successfully. I can also delete an existing variable, and re-create it, but it I would like to know the mistake I am making in the update call.
Can someone point out what I did wrong?
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
token = File.read(__dir__ + '/.gitlab-token').chomp
host = 'https://gitlab.com/'
variables_path = 'api/v4/projects/123456/variables'
env_var = 'MY_VAR'
update_uri = URI(host + variables_path + '/' + env_var)
# I've written the above this way because my actual code
# has a delete and create in order to "update" the variable
response = Net::HTTP.start(update_uri.host, update_uri.port, use_ssl: true) do |http|
update_request = Net::HTTP::Post.new(update_uri)
update_request['PRIVATE-TOKEN'] = token
form_data = [
['value', 'a new value']
]
update_request.set_form(form_data, 'multipart/form-data')
response = http.request(update_request)
response.body
end
I am trying to integrate QnAmaker knowledge base with Azure Bot Service.
I am unable to find knowledge base id on QnAMaker portal.
How to find the kbid in QnAPortal?
The Knowledge Base Id can be located in Settings under “Deployment details” in your knowledge base. It is the guid that is nestled between “knowledgebases” and “generateAnswer” in the POST (see image below).
Hope of help!
Hey you can also use python to get this by take a look at the following code.
That is if you wanted to write a program to dynamically get the kb ids.
import http.client, os, urllib.parse, json, time, sys
# Represents the various elements used to create HTTP request path for QnA Maker
operations.
# Replace this with a valid subscription key.
# User host = '<your-resource-name>.cognitiveservices.azure.com'
host = '<your-resource-name>.cognitiveservices.azure.com'
subscription_key = '<QnA-Key>'
get_kb_method = '/qnamaker/v4.0/knowledgebases/'
try:
headers = {
'Ocp-Apim-Subscription-Key': subscription_key,
'Content-Type': 'application/json'
}
conn = http.client.HTTPSConnection(host)
conn.request ("GET", get_kb_method, None, headers)
response = conn.getresponse()
data = response.read().decode("UTF-8")
result = None
if len(data) > 0:
result = json.loads(data)
print
#print(json.dumps(result, sort_keys=True, indent=2))
# Note status code 204 means success.
KB_id = result["knowledgebases"][0]["id"]
print(response.status)
print(KB_id)
except :
print ("Unexpected error:", sys.exc_info()[0])
print ("Unexpected error:", sys.exc_info()[1])
I am executing the code below as a cucumber step. The test case id is
C70. I tried a run ID and it gave the same error.
The code and error are below -
-----------------
require 'testrail-ruby'
client = TestRail::APIClient.new('https://xxxx.testrail.net')
client.user = 'xxxxxxxxxx.com'
client.password = 'xxxxxx'
r = client.send_post(
'add_result_for_case/C270',
{ :status_id => 1, :comment => 'This test worked fine!' }
)
puts r
The Error:
TestRail API returned HTTP 400 ("Field :run_id is not a valid ID.")
What am I doing wrong? I have researched this topic and have not resolved it Please advise....
I found my problem . I should have used the full Test Case ID. The ID that found when running the actual test case . The issue is resloved.
Extra suggestion.
Do not use characters other than numbers when giving the ID information. For example, when giving the case Id, it shows up as C270 in Testrail. But you have to give it as 270 in Api. In another example, let your RunId be R150. You only need to give it as 150.
I am trying to port tests from using FakeRequest to using WithServer.
In order to simulate a session with FakeRequest, it is possible to use WithSession("key", "value") as suggested in this post: Testing controller with fake session
However when using WithServer, the test now looks like:
"render the users page" in WithServer {
val users = await(WS.url("http://localhost:" + port + "/users").get)
users.status must equalTo(OK)
users.body must contain("Users")
}
Since there is no WithSession(..) method available, I tried instead WithHeaders(..) (does that even make sense?), to no avail.
Any ideas?
Thanks
So I found this question, which is relatively old:
Add values to Session during testing (FakeRequest, FakeApplication)
The first answer to that question seems to have been a pull request to add .WithSession(...) to FakeRequest, but it was not applicable to WS.url
The second answer seems to give me what I need:
Create cookie:
val sessionCookie = Session.encodeAsCookie(Session(Map("key" -> "value")))
Create and execute request:
val users = await(WS.url("http://localhost:" + port + "/users")
.withHeaders(play.api.http.HeaderNames.COOKIE -> Cookies.encodeCookieHeader(Seq(sessionCookie))).get())
users.status must equalTo(OK)
users.body must contain("Users")
Finally, the assertions will pass properly, instead of redirecting me to the login page
Note: I am using Play 2.4, so I use Cookies.encodeCookieHeader, because Cookies.encode is deprecated