jeudi 29 novembre 2018

How to use dynamic values for Karate Features

I've a need where I should use dynamic values in the features of my karate tests.

I've came accross with some of the questions and answers like this: How to read input data from an excel spreadsheet and pass it JSON payload in karate framework?

But no mather what how hard I try, I couln't make it happen. I believe I should share the code parts that I am trying to use, so that a discussion can start.

I have a SOAP request for creating new users as below:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xxxxxx>
<soapenv:Header/>
<soapenv:Body>
    <int:createSubscriber soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <custBean xxxxx>
            <accountNumber xsi:type="xsd:string">#(accountNo)</accountNumber>
            <custName xsi:type="xsd:string" xs:type="type:string">Xbox</custName>
        </custBean>
        <addSubscriberBean xxxxx>7
            <subscriberID xsi:type="xsd:string">#(subsID)</subscriberID>
            <password xsi:type="xsd:string" xs:type="type:string">0</password>
            <areaID xsi:type="xsd:string" xs:type="type:string">1</areaID>
            <lineOfCredit xsi:type="xsd:int" xs:type="type:int"></lineOfCredit>
            <creditCycle xsi:type="xsd:int" xs:type="type:int"></creditCycle>
            <points xsi:type="xsd:int" xs:type="type:int"></points>
            <bandwidth xsi:type="xsd:int" xs:type="type:int"></bandwidth>
            <physicalPorts xsi:type="xsd:string" xs:type="type:string">8080</physicalPorts>
            <mobilePhoneNo xsi:type="xsd:string" xs:type="type:string">#(mobile)</mobilePhoneNo>
            <stbCount xsi:type="xsd:int" xs:type="type:int">5</stbCount>
            <oTTCount xsi:type="xsd:int" xs:type="type:int">10</oTTCount>
            <subscriptionType xsi:type="xsd:string" xs:type="type:string">#(subsType)</subscriptionType>
        </addSubscriberBean>
        <sequenceID xxxxx>1234567840123422700</sequenceID>
    </int:createSubscriber>
</soapenv:Body>

As you've seen, I have some variables which is going to be given from outside, and those are: accountNo, subsID, subsType and mobile.

Nw, I have a feature file where I make a call to a SOAP service byusing above file. I am assigning new values to all variables of request, so that I can create new users all the time.

Here is the example:

Feature: Create Subscriber Feature End-To-End Scenario

Background:
* url SOAP_CREATE_SUBSCRIBER_HOST

* def accountNumber = '789'
* def subscriberID = '456'
* def userMsisdn = '123'
* def subscriptionType = 'ASD'

* def createUser = read('create-user-soap.xml') # This is the above one
* replace createUser
  | token              | value               |
  | #(accountNo)       | accountNumber       |
  | #(subsID)          | subscriberID        |
  | #(mobile)          | userMsisdn          |
  | #(subsType)        | subscriptionType    |

Scenario: Create Subscriber
Given request createUser
When soap action SOAP_CREATE_SUBSCRIBER_HOST
Then status 200

And match //returnCode == 0
And match //returnMessage == 'The operation succeeded.'

However, I need to create bunch of users, so I need to use dynamic variables to call my .xml file too many times.

I checked the docs and answer here: How to read input data from an excel spreadsheet and pass it JSON payload in karate framework?

But couldn't locate it in my situation.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire