본문 바로가기
🎪 놀고있네/Katalon

[Katalon] Mobile Testing - List로 목록 저장하기

by 냥장판 2021. 2. 6.

Test Scenario: Views > Radio Group 에서 라디오버튼으로 되어있는 radio element를 List에 저장하고, 임의의 라디오 버튼 클릭하기

 

 

Webdriver와 List를 사용해서 element 목록 저장하는 것을 해볼게요.

스크립트 시나리오는 Views > Radio Group 에서

라디오버튼으로 되어있는 radio element를 findElementClassName을 사용해서 찾아내고,

List에 저장하여 리스트 중 임의의 라디오 버튼을 클릭하는 거에요.

 

 

Record Mobile 기능사용하는 포스트는 아래를 참고하세요.

여기서 썼던 Object 들을 이번 포스팅에서도 똑같이 사용합니다.

2021/02/06 - [🎪 놀고있네/Katalon] - [Katalon] Mobile Testing - Record Mobile

 

[Katalon] Mobile Testing - Record Mobile

Katalon Studio에서 Record Mobile 기능을 사용해볼게요 Android apk 파일은 Katalon에서 제공하니 다운로드 하시면 됩니다. docs.katalon.com/katalon-studio/docs/scroll_element_mobile_automation.html#scrol..

miaow-miaow.tistory.com

 

 

 

 

 

우선, 필요한 패키지들을 import 합니다.

 

아래 소스 첨부했습니다.

1
2
3
4
5
6
7
8
9
10
11
import org.openqa.selenium.WebElement as WebElement
 
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration
 
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
 
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
 
import com.kms.katalon.core.model.FailureHandling as FailureHandling
 
import io.appium.java_client.AppiumDriver as AppiumDriver
cs

 

 

List로 저장하길 원하는 element를 확인하고 싶으면(특히 element의 class name),

Spy나 Record Mobile를 통해 확인이 가능합니다

 

라디오버튼의 클래스명은 android.widget.RadioButton 으로 되어있어요.

 

 

아래에 보면 driver.findElementsByClassName() 안에 이 android.widget.RadioButton 가 들어가게 됩니다.

for문으로 된 부분은

webelement 중에 list로 저장하는(Radio Button) element에서 텍스트를 얻어와서

Dinner와 일치하면 해당 element를 클릭하는 로직입니다.

실행화면은 아래와 같아요.

 

매뉴얼모드와 소스 첨부합니다.

 

 

 

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
 
'Path of the Apk File Store in path variable'
def path = RunConfiguration.getProjectDir() + '/Androidapp/APIDemos.apk'
 
'Start the application'
Mobile.startApplication(path,true)
 
Mobile.scrollToText('Views')
 
Mobile.tap(findTestObject('Object Repository/TestMobile_List/android.widget.TextView - Views'), 0)
 
Mobile.scrollToText('Radio Group')
 
Mobile.tap(findTestObject('Object Repository/TestMobile_List/android.widget.TextView - Radio Group'), 0)
 
'Initializing Appium Driver' 
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
 
'Getting all similar elements and storing in to List' 
List<WebElement> elements = driver.findElementsByClassName('android.widget.RadioButton')
 
'Printing the Size of list elements'
println('The size of elements is ::' + elements.size())
 
for (WebElement radiobtn : elements) {
 
    'Get the text of each element in the list and store in to the "actual_Text" variable.'
    String actual_Text = radiobtn.getText()
    
    println(actual_Text)
 
     'Here verifying the actual text with expected text of "Dinner" on every iteration' 
     if(actual_Text.equals("Dinner"))
     {
 
           'Click on expected Element "Dinner" '
           radiobtn.click()
 
           'Break the loop'
           break
 
     }
 
}
cs

 

그럼 이만!

 

 

참고

docs.katalon.com/katalon-studio/docs/store_mobile_elements_to_validate_data.html#script-mode

 

Using List to Store the Mobile Elements to Validate Data

To select a mobile element (ex: Radio button) from a List, we need to capture all the button elements in a collection and pick the desired Radio button.

docs.katalon.com

 

댓글