For loop case with different invoice number

Hello
Can any one guide me that how to create multiple invoice in loop. Kindly check out attachment and guide me. Thank you

Instead than a for loop, how about a while loop? I assume you can read the “Invoice #” from the sheet, so loop until either you get the next “Invoice #” or you get no “Item_name”.

  1. You need a means to stop the whole process and I would think that would be no more item_code or/and item_name.
  2. Since you didn’t stop from the line above, then you need to check if the line is a “new” supplier/invoice (and setup new supplier and process the “line” if it is).
  3. Since it is not a “new” supplier/invoice, then process the “line” for the current supplier/invoice.
Maybe like:

I’m certain you can simplify the below code once you know what you need to do such as making a Keyword of your invoice processing. I have given you isNewSupplier that can assist should you need additional conditional processing. Edit: I changed back to a for loop.

boolean isFinished = false;  // use to stop the loop of the whole 
boolean hasSupplier = false;  // use to indicate that have no supplier at beginning
boolean isNewSupplier = false;  // use to indicate that a new supplier and invoice

int row = 1;  // the row of the spreadsheet
float netAmt = 0.0  // the accumulating total of the invoice's net amount
float taxAmt = 0.0  // the accumulating total of the invoice's tax amount
float grossAmt = 0.0  // the accumulating total of the invoice's gross amount

def info = ["Supplier": "", "InvoiceNum": "", "SupplierName": "", "PODate": "", 
	"RequiredByDate": "", "ItemCode": "", "ItemName": "", "Quantity": "", "Rate": "",
	"Discount": "", "GrossAmount": "", "TaxRate": "", "TaxAmount": "", "ItemNetAmount": ""]

def data = TestDataFactory.findTestData("Data Files/TestCSV")

for (row = 1; row <= data.getRowNumbers(); row++) {

	if (data.getValue(6, row) == "" && data.getValue(7, row) == "") {
		// if there is no itemCode and itemName then stop
	   isFinished = true
	} else {
		info.InvoiceNum = data.getValue(2, row)

		info.GrossAmount = data.getValue(11, row)
		info.TaxAmount = data.getValue(13, row)
		info.ItemNetAmount = data.getValue(14, row)
		if (info.InvoiceNum != "") {
			if (!hasSupplier) {
				// have nothing to display or print out on the very first time
				hasSupplier = true
			} else {
				WebUI.comment("For ${info.InvoiceNum}, the net amount is ${netAmt}")
				WebUI.comment("For ${info.InvoiceNum}, the tax amount is ${taxAmt}")
				WebUI.comment("For ${info.InvoiceNum}, the gross amount is ${grossAmt}")
			}
			netAmt = 0.0
			taxAmt = 0.0
			grossAmt = 0.0
			WebUI.comment("Net amount is ${info.ItemNetAmount}")
			WebUI.comment("Tax amount is ${info.TaxAmount}")
			WebUI.comment("Gross amount is ${info.GrossAmount}")
			// do your processing here for an invoice
			netAmt += Float.parseFloat(info.ItemNetAmount)
			taxAmt += Float.parseFloat(info.TaxAmount)
			grossAmt += Float.parseFloat(info.GrossAmount)

		} else {
			isNewSupplier = false

			WebUI.comment("Net amount is ${info.ItemNetAmount}")
			WebUI.comment("Tax amount is ${info.TaxAmount}")
			WebUI.comment("Gross amount is ${info.GrossAmount}")
			// do your processing here for an invoice
			netAmt += Float.parseFloat(info.ItemNetAmount)
			taxAmt += Float.parseFloat(info.TaxAmount)
			grossAmt += Float.parseFloat(info.GrossAmount)	
		
		}
	}
	
	WebUI.comment("For ${info.InvoiceNum}, the net amount is ${netAmt}")
	WebUI.comment("For ${info.InvoiceNum}, the tax amount is ${taxAmt}")
	WebUI.comment("For ${info.InvoiceNum}, the gross amount is ${grossAmt}")
}

Thank you dear, let me try “While”

can you guide me that

(//input[@type=‘text’])[27]
(//input[@type=‘text’])[22]

how to merge 2 Xpath together

The xpaths you show are two different elements (the twenty-second element with a “type” attribute of text and the twenty-seventh element with a “type” attribute of text). If you tried to merge them together, you would not get any element because now the pathway does not show the computer an unique element.

If you want to get two attributes of one element so that you can uniquely identify it, you can use and, such as:

//input[@type="text" and @value="second"]

But again, just putting the two paths you show would not get you an xpath to an element. Otherwise, we would need more information on what you were trying to do.

Edit: I had a thought that you might want to add the “contents” of the two text fields. Is that what you want to do?

Hello , getting this error

Elapsed time: 0.048s

Test Cases/Projects/WEB/DGTX_WEB/Modules/Collection/Purchase Order - Copy FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: TestDataFactory for class: Script1631429767258
at Purchase Order - Copy.run(Purchase Order - Copy:52)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:430)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:421)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:400)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:392)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:273)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1631430910246.run(TempTestCase1631430910246.groovy:25)

Reason:
groovy.lang.MissingPropertyException: No such property: isFinished for class: Script1631429767258
at Purchase Order - Copy.run(Purchase Order - Copy:49)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:430)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:421)

For the above concern, the import statement for TestDataFactory is not in your list of import statements at the top of your code. It doesn’t have to be the first but just in the list of statements.
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory

If you hit CTRL + SHIFT + O (oh) then all the necessary import statements will be included in your program. Note some will be removed if they are not used in your code.

For this concern, it sounds like you are missing the definition of the variable like below (see the very first line in my thought bubble below):
boolean isFinished = false; // use to stop the loop of the whole

Maybe like:

I have updated the code somewhat to put it into a for loop, added gross amount and changed the values into float data types.

boolean isFinished = false;  // use to stop the loop of the whole 
boolean hasSupplier = false;  // use to indicate that have no supplier at beginning
boolean isNewSupplier = false;  // use to indicate that a new supplier and invoice

int row = 1;  // the row of the spreadsheet
float netAmt = 0.0  // the accumulating total of the invoice's net amount
float taxAmt = 0.0  // the accumulating total of the invoice's tax amount
float grossAmt = 0.0  // the accumulating total of the invoice's gross amount

def info = ["Supplier": "", "InvoiceNum": "", "SupplierName": "", "PODate": "", 
	"RequiredByDate": "", "ItemCode": "", "ItemName": "", "Quantity": "", "Rate": "",
	"Discount": "", "GrossAmount": "", "TaxRate": "", "TaxAmount": "", "ItemNetAmount": ""]

def data = TestDataFactory.findTestData("Data Files/TestCSV")

for (row = 1; row <= data.getRowNumbers(); row++) {

	if (data.getValue(6, row) == "" && data.getValue(7, row) == "") {
		// if there is no itemCode and itemName then stop
	   isFinished = true
       break;
	} else {
		info.InvoiceNum = data.getValue(2, row)

		info.GrossAmount = data.getValue(11, row)
		info.TaxAmount = data.getValue(13, row)
		info.ItemNetAmount = data.getValue(14, row)
		if (info.InvoiceNum != "") {
			if (!hasSupplier) {
				// have nothing to display or print out on the very first time
				hasSupplier = true
			} else {
				// display the amounts when change supplier
				WebUI.comment("For ${info.InvoiceNum}, the net amount is ${netAmt}")
				WebUI.comment("For ${info.InvoiceNum}, the tax amount is ${taxAmt}")
				WebUI.comment("For ${info.InvoiceNum}, the gross amount is ${grossAmt}")
			}
			netAmt = 0.0
			taxAmt = 0.0
			grossAmt = 0.0
			WebUI.comment("Net amount is ${info.ItemNetAmount}")
			WebUI.comment("Tax amount is ${info.TaxAmount}")
			WebUI.comment("Gross amount is ${info.GrossAmount}")
			// do your processing here for an invoice
			netAmt += Float.parseFloat(info.ItemNetAmount)
			taxAmt += Float.parseFloat(info.TaxAmount)
			grossAmt += Float.parseFloat(info.GrossAmount)

		} else {
			isNewSupplier = false

			WebUI.comment("Net amount is ${info.ItemNetAmount}")
			WebUI.comment("Tax amount is ${info.TaxAmount}")
			WebUI.comment("Gross amount is ${info.GrossAmount}")
			// do your processing here for an invoice
			netAmt += Float.parseFloat(info.ItemNetAmount)
			taxAmt += Float.parseFloat(info.TaxAmount)
			grossAmt += Float.parseFloat(info.GrossAmount)	
		
		}
	}
}
WebUI.comment("For ${info.InvoiceNum}, the net amount is ${netAmt}")
WebUI.comment("For ${info.InvoiceNum}, the tax amount is ${taxAmt}")
WebUI.comment("For ${info.InvoiceNum}, the gross amount is ${grossAmt}")