This post was most recently updated on July 25th, 2017
It it very easy to get data from excel using Katalon Studio. For Data driven test cases we need excel sheet. In this article will see how to use excel sheet in KATALON studio by using findTestData method.
- Select Menu File -> New -> Test Data (Katalon studio will show “New Test Data” Dialog.
- Provide Test Data Name in “Name” Text box.
- Select “Excel” from data type dropdown list.
- Provide Description if required and then click on Ok Button. (File’s Information Window should appear)
- Select File Name which you want to use as test data by clicking on Browse Button
- By default “use first row as header” is checked. Don’t uncheck it.
- Now select the sheet name and then click on Save All.
Now in script define variable for e.g
url = findTestData(“New Test Data”).getValue(“url”, 1)
in findTestData method pass the parameter name of Test Data which you have created by following step 1 to 7 and then provide column name and row number in getValue.
Below is the sample code to read input values from excel sheet and pass it to script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase import static com.kms.katalon.core.testdata.TestDataFactory.findTestData import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject import java.text.BreakIterator as BreakIterator import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile import com.kms.katalon.core.model.FailureHandling as FailureHandling import com.kms.katalon.core.testcase.TestCase as TestCase import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory import com.kms.katalon.core.testdata.TestData as TestData import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository import com.kms.katalon.core.testobject.TestObject as TestObject import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords import com.machinepublishers.jbrowserdriver.Alert as Alert import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI import internal.GlobalVariable as GlobalVariable import javafx.scene.control.Alert.AlertType as AlertType import org.openqa.selenium.Keys as Keys import org.openqa.selenium.WebElement as WebElement import org.openqa.selenium.server.htmlrunner.HTMLSuiteResult.HrefConverter as HrefConverter import org.apache.jasper.tagplugins.jstl.core.If as If import org.apache.poi.hssf.record.PageBreakRecord.Break as Break import org.openqa.selenium.By as By import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory WebUI.openBrowser(null) url = findTestData("New Test Data").getValue("url", 1) keyword = findTestData("New Test Data").getValue("keyword", 1) urlToSearch = findTestData("New Test Data").getValue("keyword", 1) WebUI.maximizeWindow() WebUI.navigateToUrl(url) WebUI.setText(findTestObject('Page_Google/input_q'), keyword) WebUI.sendKeys(findTestObject('Object Repository/Page_Google/input_q'), Keys.chord(Keys.RETURN)) 'In Object we have added one link now we are modifying that object' 'by setting URL = http://www.societyhive.com/' l1: for (int j = 1; j <= 4; j++) { String xpathval = ((('//*[@id=' + '\"rso\"') + ']/div/div/div[') + j) + ']/div/div/h3/a' LinkToSearch = WebUI.modifyObjectProperty(findTestObject('Object Repository/resultPage/resultLink'), 'xpath', 'equals', xpathval, true) LinkVal = WebUI.getAttribute(LinkToSearch, 'href', FailureHandling.STOP_ON_FAILURE) if (LinkVal == urlToSearch) { WebUI.click(LinkToSearch, FailureHandling.STOP_ON_FAILURE) Break l1 } } WebUI.closeBrowser() |
i am not able to upload csv, xlsx sheet here is the screenshot,.
http://prntscr.com/nc4q83
Gracias
How to write data into excel using Katalon?
Thank you, Venkatesh for your comment. We will look into your request.
Thank you for your tutorials!
For people who don’t know, we can learn how to approach to data driven testing through this article on Katalon Studio site:
https://www.katalon.com/resources-center/tutorials/data-driven-testing/
Thank you James for your comment.