Appium简介及原理
Appium是一个开源、跨平台的测试框架,可以用来测试原生及混合的移动端应用。Appium支持iOS、Android及FirefoxOS平台。它使用WebDriver的JSON Wire协议来驱动iOS系统的UIAutomation库以及Android系统的UIAutomator框架。它允许自动化人员在不同的平台(iOS,Android)使用同一套API来写自动化脚本,这样大大增加了iOS和Android的代码复用性。
整个Appium分为Client和Server:Client封装了Selenium客户端类库,为用户提供所有常见的Selenium命令以及额外的移动设备控制相关的命令,如多点触控手势和屏幕朝向等;Server定义了官方协议的扩展,为用户提供了方便的接口来执行各种设备动作,例如在测试过程中安装/卸载App等。
Appium支持多种编程语言开发自动化程序,这取决于它选择了Client/Server的设计模式。Client通过发送HTTP请求给Server,当Server接收Client发送的请求时,会解析请求内容并调用对应的系统框架,在移动设备上执行自动化操作。因为Client和Server之间采用HTTP协议,所以Client用什么语言来开发自动化程序都是可以的。Appium的工作原理如图所示。
从Appium的原理图可以看到,Appium-Client能为我们提供自动化功能模块,用于编写自动化程序。在Python中,它是第三方模块Appium,该模块是在Selenium库的基础上进行封装。Appium-Server是基于Node.JS开发的服务端,主要接收Appium-Client的请求,然后根据请求信息操作移动设备,从而实现自动化操作。
import unittest
import os
import copy
import sys
from time import sleep
from appium import webdriver
from helpers import report_to_sauce, ANDROID_BASE_CAPS, EXECUTOR
from selenium.common.exceptions import WebDriverException
# Run standard unittest base.
class TestAndroidCreateSession(unittest.TestCase):
def tearDown(self):
report_to_sauce(self.driver.session_id)
def test_should_create_and_destroy_android_session(self):
caps = copy.copy(ANDROID_BASE_CAPS)
caps['name'] = 'test_should_create_and_destroy_android_session'
self.driver = webdriver.Remote(
command_executor=EXECUTOR,
desired_capabilities=caps
)
self.driver.implicitly_wait(10)
# make sure the right package and activity were started
self.assertEquals('io.appium.android.apis', self.driver.current_package)
self.assertEquals('.ApiDemos', self.driver.current_activity)
self.driver.quit()
sleep(5)
# should not be able to use the driver anymore
with self.assertRaises(WebDriverException) as excinfo:
self.driver.title
self.assertTrue('has already finished' in str(excinfo.exception.msg))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。