Hybrid Application

  • 네이티브 앱 형태로 만들되 그 안에서 웹사이트를 띄울 수 있는 브라우저 창을 두는 앱
  • 장점
    • 네이티브 수준의 구현을 업데이트 할 때만 마켓 검수가 필요하고 웹뷰에서 나타나는 컨테츠는 웹 사이트만 수정하기 되기 때문에 훨씬 더 유연하게 개발가 유지보수가 가능함 

 

사전 준비

  • 사전에 크롬드라이버가 설치 되어있어야 한다.

 

웹뷰 모드로 접근

  • 크롬 드라이버 로드 및 웹뷰 모드 on
desired_caps['chromedriverExecutable'] = 'D:\Test_Appium\chromedriver.exe'
desired_caps['autoWebview'] = True
 
  • 자동화 컨텍스트 설정
webview = driver.contexts[1]
driver.switch_to.context(webview)
 
 

만약 Native 메뉴로 접근해야한다면?

  • 해당 메뉴에 접근 할때는 아래와 같이 스위칭을 해줘야 한다.
driver.switch_to.context('NATIVE_APP')
 
  • 다시 웹뷰로 접근할때는 아래와 선언해줍니다.
driver.switch_to.context(webview)
 

예제 소스

'''
Test App
Device: emulator-5554
'''
import unittest
from appium import webdriver
from time import sleep
import os
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from appium.webdriver.common.touch_action import TouchAction
 
class LoginTest(unittest.TestCase):
 
    def setUp(self):    
        desired_caps = {}
        desired_caps['platformName'] = 'ANDROID'
        desired_caps['platformVersion'] = '12'
        desired_caps['deviceName'] = 'device1'
        desired_caps['udid'] = 'emulator-5554'
        desired_caps['automationName'] = 'Appium'        
        desired_caps['chromedriverExecutable'] = 'D:\Test_Appium\chromedriver.exe'
        desired_caps['appPackage'] = 'com.xxx.xxxx'
        desired_caps['appActivity'] = 'com.xxx.xxxx'
        desired_caps['unicodeKeyboard'] = True
        desired_caps['resetKeyboard'] = True
        desired_caps['autoWebview'] = True
        desired_caps['noReset'] = True
 
 
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
 
    def testRun(self):      
 
        driver = self.driver       
        wait = WebDriverWait(driver, 20)
        # switch to webview
        webview = driver.contexts[1]
        driver.switch_to.context(webview)
        mainloginbtn = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#topArea > nav > ul > li.xans-element-.xans-layout.xans-layout-statelogoff > a')))
        mainloginbtn.click()
         
        id = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#member_id')))       
        id.click()
        id.send_keys('toast')
         
        pw = driver.find_element(By.CSS_SELECTOR, '#member_passwd')
        pw.click()
        pw.send_keys('1234')
         
        loginbtn = driver.find_element(By.CSS_SELECTOR, '#member_login_module_id > div > fieldset > div > div.ec-base-button.gFull > button')
        loginbtn.click()
         
        sleep(8)
 
    def tearDown(self):
        self.driver.quit()
  
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(LoginTest)
    unittest.TextTestRunner(verbosity=2).run(suite)

'APP Test > Appium' 카테고리의 다른 글

Linux 자동화 환경 구성  (0) 2022.06.07
Appium Automation Framework from Java, Maven, TestNG  (0) 2020.08.10
블로그 이미지

정신차려이각박한세상속에서

,