/ KATALON STUDIO

WebUI Element 4

Index

Set Text

Verify Text Not Present

Verify Text Present

Upload File

Modify Object Property

Remove Object Property


1. Set Text

  • Description

    타이핑하는 것 처럼 input 필드의 값을 설정한다. 인풋 필드의 이전 값은 초기화한다.

  • Parameter

Param Param Type Mandatory Description
to TestObject Required 나타내려는 web element
text String Required 타이핑 하려는 텍스트
flowControl FailureHandling Optional failure handlingschema를 지정하면 실행을 계속할지 중지할지 결정할 수 있다.
  • Example


WebUI.setText(findTestObject('Object Repository/Google/Page_ - Google/input_Google_identifier'), 'zozon1330@gmail.com')


2. Verify Text Not Present

  • Description

    주어진 텍스트가 해당 페이지 소스에 표시되지 않는지 확인한다.

  • Parameter

Param Param Type Mandatory Description
text String Required 이 텍스트가 표시되지 않으면 verified
isRegex Boolean Required 예상 텍스트가 일반 표현식인지 여부를 나타냅니다.
flowControl FailureHandling Optional failure handlingschema를 지정하면 실행을 계속할지 중지할지 결정할 수 있다.
  • Returns

Param Types Description
Boolean true일 경우 주어진 텍스트가 페이지 소스 내에 없다. (false 는 반대)
  • Example


3. Verify Text Present

  • Description

    주어진 텍스트가 해당 페이지 소스에 표시되는지 확인한다.

  • Parameter

Param Param Type Mandatory Description
text String Required 이 텍스트가 표시된다면 verified
isRegex Boolean Required 예상 텍스트가 일반 표현식인지 여부를 나타냅니다.
flowControl FailureHandling Optional failure handlingschema를 지정하면 실행을 계속할지 중지할지 결정할 수 있다.
  • Returns

Param Types Description
Boolean true일 경우 주어진 텍스트가 페이지 소스 내에 있다. (false 는 반대)
  • Example

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fileupload_get')

isPresent = WebUI.verifyTextPresent("Try it", false)

isNotPresent = WebUI.verifyTextNotPresent("로그인",false)


4. Upload File

  • Description

    타이핑하는 것 처럼 input 필드의 값을 설정한다. 인풋 필드의 이전 값은 초기화한다.

  • Parameter

Param Param Type Mandatory Description
to TestObject Required 나타내려는 web element
fileAbsolutePath String Required 로컬 기기의 절대 경로
flowControl FailureHandling Optional failure handlingschema를 지정하면 실행을 계속할지 중지할지 결정할 수 있다.
  • Example


WebUI.uploadFile(findTestObject('input_browse'), 'D:\\test-photo.png')


5. Modify Object Property

  • Description

    기존 속성을 수정하거나 테스트 개체에 새 속성을 추가하십시오. 테스트 객체의 속성이 런타임에 변할 때 사용하십시오. 이 키워드는 Object Repository에 저장된 객체를 수정하지 않고 대신 다른 테스트 객체를 만들고이 테스트 객체를 수정하여 반환합니다. 따라서 사용자는 반환 된 객체를 저장하기 위해 변수를 사용해야합니다.

  • Parameter

Param Param Type Mandatory Description
testObject TestObject Required 웹 요소를 나타냄
propertyName String Required property 이름 (eg: xpath, id, name 등) 관련 아티팩트를 수정함. 없으면 추가.
matchCondition String Required property 이름과 property 값의 조건 (eg: equals, not equals 등) 만약 이미 있는 property라면 null을 입력하면 이전 조건이 유지됨
modifyValue String Required property의 값. property가 이미 존재할 때 null을 입력하면 이전 값이 유지됨
isActive Boolean Required property가 확인되면 true(test object를 찾는데 사용)
flowControl FailureHandling Optional failure handlingschema를 지정하면 실행을 계속할지 중지할지 결정할 수 있다.
  • Returns

Param Types Description
TestObject 새롭게 생성된 TestObject
  • Example

개체 “btn_Login”의 “xpath”속성을 수정하고 수정 된 개체를 “new_btn”으로 저장함.


'Modify xpath of \'Login\' button'
new_btn = WebUI.modifyObjectProperty(findTestObject('Page_Login/btn_Login'), 'xpath', 'equals', '//*[@type=\"button\"]', false)



6. Remove Object Property

  • Description

테스트 개체의 기존 속성을 제거합니다. 테스트 객체의 속성이 런타임에 변할 때 사용하십시오. 이 키워드는 Object Repository에 저장된 객체를 수정하지 않고 다른 테스트 객체를 만들고이 테스트 객체를 수정 및 반환합니다. 따라서 사용자는 반환 된 객체를 저장하기 위해 변수를 사용해야합니다.

  • Parameter

Param Param Type Mandatory Description
testObject TestObject Required web element를 나타냄
propertyName String Required property 이름 (eg: xpath, id, name 등)
flowControl FailureHandling Optional failure handlingschema를 지정하면 실행을 계속할지 중지할지 결정할 수 있다.
  • Returns

Param Types Description
TestObject 새롭게 생성된 TestObject
  • Example

“btn_Login”개체의 “class”속성을 제거하고 수정 된 개체를 “new_btn”으로 저장하려고합니다.


'Remove property class of \'Login\' button'
new_btn = WebUI.removeObjectProperty(findTestObject('Page_Login/btn_Login'), 'class')


Addition

Unable to click on object

Error

Reason: com.kms.katalon.core.exception.StepFailedException: Unable to click on object ‘Object Repository/Google/Page_ - Google/div_password_next’

Reason

  1. element가 div로 wrapping 되어있어서 div를 대신 클릭함
  2. element가 실제로 페이지에 보이지 않는다 클릭을 적용하려고 할 때

Solution

  1. web spy로 div가 아닌 content 영역을 잡음 (글씨 등이 될 수 있는데 정확하지 않음)
  2. Custom Keyword를 이용해 JavascriptExecutor를 사용
	/**
	 * Click element using Javascript
	 */
	@Keyword
	def clickUsingJS(TestObject to, int timeout)
	{
		WebDriver driver = DriverFactory.getWebDriver()
		WebElement element = WebUiCommonHelper.findWebElement(to, timeout)
		JavascriptExecutor executor = ((driver) as JavascriptExecutor)
		executor.executeScript('arguments[0].click()', element)
	}
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 com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
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.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import Script.myKeywords
import internal.GlobalVariable as GlobalVariable

WebUI.openBrowser('')

WebUI.navigateToUrl('https://accounts.google.com/signin/v2/identifier?service=accountsettings&hl=ko&continue=https%3A%2F%2Fmyaccount.google.com%2Fintro%3Futm_source%3DOGB%26tab%3Drk%26utm_medium%3Dapp&csig=AF-SEnZTU2xGrulBre0H%3A1552454767&flowName=GlifWebSignIn&flowEntry=ServiceLogin')

WebUI.setText(findTestObject('Object Repository/Google/Page_ - Google/input_Google_identifier'), 'zozon1330@gmail.com')

WebUI.click(findTestObject('Object Repository/Google/Page_ - Google/content_next'))

WebUI.setEncryptedText(findTestObject('Object Repository/Google/Page_ - Google/input_password'), 'hKiSU0KEpwcBg1/3uNKmPA==')

CustomKeywords.'Script.myKeywords.clickUsingJS'(findTestObject('Object Repository/Google/Page_ - Google/div_password_next'), 30)