Appium官方文档常用方法介绍

Appium命令 · Appium 官方文档 · 看云

创建Session

// Java
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.3");
desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
desiredCapabilities.setCapability(MobileCapabilityType.APP, "/path/to/ios/app.zip");

URL url = new URL("http://127.0.0.1:4723/wd/hub");

IOSDriver driver = new IOSDriver(url, desiredCapabilities);
String sessionId = driver.getSessionId().toString();

# Python
desired_caps = {
  'platformName': 'Android',
  'platformVersion': '7.0',
  'deviceName': 'Android Emulator',
  'automationName': 'UiAutomator2',
  'app': PATH('/path/to/app')
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

向下滑动实现方法

// Java
driver.executeScript("mobile: scroll", ImmutableMap.of("direction", "down"));

# Python
self.driver.execute_script("mobile: scroll", {'direction': 'down'})

屏幕截图

对当前的视窗(viewport)、窗口(window)、页面(page)进行截图

使用样例

// Java
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

# Python
screenshotBase64 = self.driver.get_screenshot_as_base64()

设置隐式等待超时时间

设置在查找元素时driver必须等待的时间量

使用样例

// Java
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

# Python
self.driver.implicitly_wait(5) # waits 5 seconds

设置超时

为特定类型的操作执行配置时间量,超过时间后操作会被终止。

使用样例

// Java
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

# Python
self.driver.set_page_load_timeout(5000)

获取显示方向

获取当前设备/浏览器的显示方面(横屏/竖屏)

使用样例

// Java
ScreenOrientation orientation = driver.getOrientation();

# Python
orientation = self.driver.orientation

获得地理位置

获得当前的地理位置

使用样例

// Java
Location location = driver.location(); // Must be a driver that implements LocationContext

# Python
location = self.driver.location()

设置地理位置

设置当前的地理位置

使用样例

// Java
driver.setLocation(new Location(49, 123, 10)); // Must be a driver that implements LocationContext

# Python
self.driver.set_location(49, 123, 10)

获得日志对象

获得给定日志类型的日志对象。在每次请求之后日志缓存被重置。

使用样例

// Java
LogEntries logEntries = driver.manage().logs().get("driver");

# Python
logs = driver.get_log('driver');

获取当前的Activity名称

得到当前的Android Activity名称

使用样例

// Java
String activity = driver.currentActivity();

# Python
activity = self.driver.current_activity;

开始屏幕录制

开始屏幕录制

用法示例

// Java
driver.startRecordingScreen();
driver.startRecordingScreen(new BaseStartScreenRecordingOptions(....));
# Python
self.driver.start_recording_screen()

停止屏幕录制

停止屏幕录制

用法示例

// Java
driver.stopRecordingScreen();
driver.stopRecordingScreen(new BaseStopScreenRecordingOptions(....));
# Python
self.driver.stop_recording_screen()

相关推荐

  1. Appium官方文档方法介绍

    2024-03-22 19:54:03       46 阅读
  2. 传感器误差补偿方法介绍

    2024-03-22 19:54:03       24 阅读
  3. Python配置文件读取方法

    2024-03-22 19:54:03       50 阅读
  4. FileUtils类中方法介绍

    2024-03-22 19:54:03       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-22 19:54:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-22 19:54:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-22 19:54:03       87 阅读
  4. Python语言-面向对象

    2024-03-22 19:54:03       96 阅读

热门阅读

  1. C++ 虚函数和多态

    2024-03-22 19:54:03       39 阅读
  2. MPI4.1文档3-MPI过程与MPI数据类型

    2024-03-22 19:54:03       36 阅读
  3. 1064:奥运奖牌计数

    2024-03-22 19:54:03       44 阅读
  4. c++算法学习笔记 (14) 并查集

    2024-03-22 19:54:03       39 阅读
  5. SpringBoot自定义starter开发:定时任务报表开发

    2024-03-22 19:54:03       37 阅读
  6. Rust无法流行起来

    2024-03-22 19:54:03       45 阅读
  7. sqlite简单的增删改查

    2024-03-22 19:54:03       45 阅读
  8. 什么是设计模式?

    2024-03-22 19:54:03       43 阅读
  9. Springboot vue elementui 超市管理系统

    2024-03-22 19:54:03       37 阅读