How to set two property value using groovy in the same time from a text file

parisFoxparis

i want to test the GetWeather webservice

http://www.webservicex.com/globalweather.asmx

I have a text file with this content: montreal canada calgary canada

My request is:

 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET">
       <soap:Header/>
       <soap:Body>
          <web:GetWeather>
             <!--Optional:-->
             <web:CityName>${#Project#City}</web:CityName>
             <!--Optional:-->
             <web:CountryName>${#Project#Country}</web:CountryName>
          </web:GetWeather>
       </soap:Body>
    </soap:Envelope>

My Groovy code is:

def f = new File("c:\\temp\\Data.txt") 
def fr= new FileReader(f)

def br = new BufferedReader(fr) 
def s = br.readLine()
def x = br.readLine() 

while(s && x !=null)
{
testRunner.testCase.setPropertyValue("City",s)
testRunner.testCase.setPropertyValue("Country",x)

testRunner.runTestStepByName("GetWeather - Request 1")
s = br.readLine()
x = br.readLine()
}

But i's not reading the file. Any help please, thank you

Emmanuel Rosa

Groovy simplifies reading lines of text files. In your case since a record consists of two lines, try this:

def f = new File('c:\temp\Data.txt') 
def records = f.readLines().collate(2)

records.each {
    testRunner.testCase.setPropertyValue("City",it[0])
    testRunner.testCase.setPropertyValue("Country",it[1])

    testRunner.runTestStepByName("GetWeather - Request 1")
}

How it works

Lets assume the input file contains the following lines:

New York
USA
Istanbul
Turkey

Lines 1 and 2 are cities and lines 2 and 4 are countries. The statement f.readLines() returns a list of the file contents, like this:

[
    'New York',
    'USA',
    'Istanbul',
    'Turkey'
]

To make the data easier to work with, I turned it into a list of city and country pairs. That's what collate(2) does:

[
    ['New York', 'USA'],
    ['Istanbul', 'Turkey]'
]

With this new list, each(Closure) is used to iterate through the pairs.

records.each {
    // it[0] is the city
    // it[1] is the country
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to set Project property value using Groovy?

From Dev

Sharing data from two text file using by 2 application at same time

From Dev

Sharing data from two text file using by 2 application at same time

From Dev

Java read two text file at the same time

From Dev

How to store secret text or file using groovy

From Dev

How to return two values from single methods and set two parent class property calling function 1 time?

From Java

How to set same alignment for these two text

From Dev

How to set two image and text in same line

From Dev

How to set the dynamic value from a text box to the graph using Highcharts?

From Dev

Reading and writing to the same file from two different scripts at the same time

From Dev

How to set the value of a property to null using reflection

From Dev

How to set nested property value using FastMember

From Dev

Using Two "For" at the same time

From Dev

How to set Time property in Java using Joda-Time

From Dev

How to set the same value for two inputs for two models in a Rails form

From Dev

How to merge two rows in a same row from a text file in linux shell script

From Dev

How to set property from the inside not using setter

From Dev

How to set property from the inside not using setter

From Dev

How can I set different sensitivities for two mice at the same time?

From Dev

How can I set different sensitivities for two mice at the same time?

From Java

How to set value of input text using jQuery

From Dev

How to Extract time from text file into another text file/list

From Dev

How can I Get the property by name from type and Set Propert value using reflection in C#

From Dev

How to set checked property of checkboxes based on value from database using angular js

From Dev

How to merge data from two text file

From Dev

How to merge data from two text file

From Dev

Jenkins - Textarea parameter plugin set default value from property file?

From Dev

Reading Value from Text file to set in batch file variable

From Dev

Ramda Js: Setting property on an object using a value from the same object

Related Related

  1. 1

    How to set Project property value using Groovy?

  2. 2

    Sharing data from two text file using by 2 application at same time

  3. 3

    Sharing data from two text file using by 2 application at same time

  4. 4

    Java read two text file at the same time

  5. 5

    How to store secret text or file using groovy

  6. 6

    How to return two values from single methods and set two parent class property calling function 1 time?

  7. 7

    How to set same alignment for these two text

  8. 8

    How to set two image and text in same line

  9. 9

    How to set the dynamic value from a text box to the graph using Highcharts?

  10. 10

    Reading and writing to the same file from two different scripts at the same time

  11. 11

    How to set the value of a property to null using reflection

  12. 12

    How to set nested property value using FastMember

  13. 13

    Using Two "For" at the same time

  14. 14

    How to set Time property in Java using Joda-Time

  15. 15

    How to set the same value for two inputs for two models in a Rails form

  16. 16

    How to merge two rows in a same row from a text file in linux shell script

  17. 17

    How to set property from the inside not using setter

  18. 18

    How to set property from the inside not using setter

  19. 19

    How can I set different sensitivities for two mice at the same time?

  20. 20

    How can I set different sensitivities for two mice at the same time?

  21. 21

    How to set value of input text using jQuery

  22. 22

    How to Extract time from text file into another text file/list

  23. 23

    How can I Get the property by name from type and Set Propert value using reflection in C#

  24. 24

    How to set checked property of checkboxes based on value from database using angular js

  25. 25

    How to merge data from two text file

  26. 26

    How to merge data from two text file

  27. 27

    Jenkins - Textarea parameter plugin set default value from property file?

  28. 28

    Reading Value from Text file to set in batch file variable

  29. 29

    Ramda Js: Setting property on an object using a value from the same object

HotTag

Archive