I am unable to access variables set in the karate feature file during gatling session

I’m unable to access variables set in the karate feature file during gatling session*

Error Msg:02:35:57.473 [GatlingSystem-akka.actor.default-dispatcher-3] ERROR i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-10' crashed on session Session(CreateSubscription,1,1725397536872,Map(orderId1 -> mqj5fjxy, attempts -> 0, customerId ->3432423, requestStartTime -> 1725397536894, 2dd34680-e360-4aaa-aaf9-f325f4e8f461 -> 0),0,OK,List(ExitOnCompleteLoopBlock(attempts), GroupBlock(List(Create and Confirm Subscription),1725397536894,0,OK), ExitOnCompleteLoopBlock(2dd34680-e360-4aaa-aaf9-f325f4e8f461)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$485/1658512704@639d7e27), forwarding to the 
next onejava.util.NoSuchElementException: No attribute named 'subscription_confirmed' is defined    at io.gatling.core.session.SessionAttribute.as(Session.scala:46)

i want to set subscription_confirmed  variable as true in karate feature file and access in gatling session.
**

Subscription.feature

Feature: create Subscription feature

  Background: Obtain test data for the scenario
      * def envName = karate.env
      * def token = “1234”
      * header Authorization = 'Bearer '+token   
      * def CID = __gatling.customerId
      * def orderId = __gatling.orderId1
      * print 'Captured orderId:', orderId
      
  

    Scenario: CreateSubscription
            
          * def createPayLoad = read('classpath:tests/payLoads/CreateSubscriptions_testdata/TestData_Subscriptions.json')
          * url “endurl”
          * path  createSubscription
          And headers {correlationId: #(correlational), env: '#(envName)'}
          * createPayLoad.orderItem[0].id = orderId
          * createPayLoad.relatedParty[0].id = CID
          * request createPayLoad
          * method post
          * status 200
    

 getSubscriptionWithValidation.feature
            
            Feature: Get Subscription   
              Scenario: GetSubscription
            * def getToken = call read('classpath/test/generateToken.feature')
            * def token = getToken.response.access_token
            * header Authorization = 'Bearer '+token
            * url 'https://rest.sandbox.com/v8/subscriptions/123'
            * method get
            * status 200  
            * And match response.data[0].custom_fields.product_id__c == 123
            * def subscription_confirmed = response.data[0].custom_fields.product_instance_id__c ==  123 
            *   And karate.set('subscription_confirmed' ,subscription_confirmed )

Gatling scripts:

package performance

import io.gatling.core.scenario.Simulation
import io.gatling.core.Predef._
import com.intuit.karate.gatling.PreDef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class PerformanceRunner extends Simulation {
  
  val protocol = karateProtocol()
  protocol.nameResolver = (req, ctx) => req.getHeader("scenario")

  System.setProperty("telus.appName", "Performance")
  System.setProperty("KongFlag.value", "true")
  System.setProperty("useToken.value", "true")
  System.setProperty("karate.appName", "appname")

  val cidfeeder = csv("CustomerID.csv").circular

  val createSubscription = scenario("CreateSubscription")
    .repeat(1) {
      feed(ecidfeeder)
        .exec { session =>
          println(session("customerId").as[String])
          session
        }
        .exec(karateFeature("classpath:performance/Subscription.feature"))
        
.exec(session => {
          var confirmed = false
          var attempts = 0
          val maxAttempts = 10
          val pollInterval = 1000 // 5 seconds

          while (!confirmed && attempts < maxAttempts) {
            // Polling GET API
            exec(karateFeature("classpath:services/Zoura/getSubscriptionWithValidation.feature"))
            // Check if the response is confirmed
            if (session.contains("subscription_confirmed")) {
              confirmed = true
            } else {
              attempts += 1
              Thread.sleep(pollInterval)
            }
          }
          if (!confirmed) {
            // Handle failure, if needed
            session.markAsFailed
          }

          session
        })
    }

  setUp(
    createSubscription.inject(rampUsers(1) during (10 seconds)).protocols(protocol)
  )
}

Used Gatling version :0.9.4

3

You are setting the value correctly in the feature file, I think you are just accessing it incorrectly in the scala/gatling file, try this inside of session block to access it.

.exec(session => {
//capture the set value from the karate feature
val subscription_confirmed = session("subscription_confirmed").as[String]
println(s"Captured value from feature file is : $subscription_confirmed")
session })

if subscription_confirmed is actually a boolean value, you can change the as[String] to as[Boolean] to get back a proper boolean

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật