walterwhites/appium-module

适用于Codeception的Appium模块

1.1.1 2018-09-28 21:54 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:30 UTC


README

适用于Codeception的Appium模块

简单Appium集成,iOS和Android自动化。

Appium-codeception-module

目录

安装

只需将 walterwhites/appium-module 添加到项目的composer.json文件中

{
    "require": {
       "walterwhites/appium-module": "dev-master"
    }
}

然后运行 composer install

测试

iOS配置

class_name: IosTester
modules:
  enabled:
    # Enable appium module
    -  \Appium\Appium:
    -  Asserts:
  config:
    # Configuration for appium module
    \Appium\Appium:
      host: 0.0.0.0
      local: true
      port: 4723
      browserName: ''
      desiredCapabilities:
        platformName: iOS
        platformVersion: '13.2'
        deviceName: iPhone 11 Pro
        xcodeOrgId: ''
        xcodeSigningId: iPhone Developer
        noReset: true
        fullReset: false
        clearSystemFiles: true
        automationName: XCUITest
        bundleId: %IOS_BUNDLE_ID%
        #app: %IOS_APP_PATH%
        #bundleId: bundleId-of-your-app
        showIOSLog: false

生成测试者类

要为在 android.suite.ymlios.suite.yml 中定义的 AndroidTester/IosTester 生成actor类,请运行以下命令

codecept build

用法

以下是一个经典的注册方法示例

/**
 * @group register
 * Tests the sign up
 * @param User $params
 */
public function registerByEmail(User $params)
{
    $this->test->clickOnButton('SIGN UP', 400);
    $this->test->clickOnButton('SIGN UP WITH EMAIL', 400);
    $this->test->setText('First name', $params->firstName);
    $this->test->setText('Last name', $params->lastName);
    $this->test->setText('Email address', $params->email);
    $this->test->hideKeyboard();
    sleep(2);
    $this->test->touchPositionedButon(2);
    sleep(2);
    $this->test->touchPositionedButon(3);
    $this->test->clickOnButton('SIGN UP', 300);
}
  • clickOnButton 点击标签为 'SIGN UP' 的按钮,然后点击 'SIGN UP WITH EMAIL'
  • setText 更新文本字段值 'First name' 为 $params->firstName
  • hideKeyboard 关闭键盘(在所有iOS设备上可能不起作用)
  • touchPositionedButton 根据其位置点击按钮或复选框

AppTestCase

protected $locatorStrategy = ILocatorStrategy::class_chain;
protected $classChainSearch = IClassChainSearch::label;
use Button;
use TextField;

public function setLocatorStrategy($locatorStrategy)
{
    switch ($locatorStrategy) {
        case ILocatorStrategy::class_chain:
            $this->locatorStrategy = ILocatorStrategy::class_chain;
            break;
        case ILocatorStrategy::predicate_string:
            $this->locatorStrategy = ILocatorStrategy::predicate_string;
            break;
        case ILocatorStrategy::accessibility_id:
            $this->locatorStrategy = ILocatorStrategy::accessibility_id;
            break;
    }
}

public function setClassChainSearch($classChainSearch)
{
    switch ($classChainSearch) {
        case IClassChainSearch::label:
            $this->locatorStrategy = IClassChainSearch::label;
            break;
        case IClassChainSearch::name:
            $this->locatorStrategy = IClassChainSearch::name;
            break;
        case IClassChainSearch::value:
            $this->locatorStrategy = IClassChainSearch::value;
            break;
    }
}

ILocatorStrategy接口

默认的定位策略是类链,您可以使用以下语句重写它

$this->test->setLocatorStrategy(ILocatorStrategy::accessibility_id);

IClassChainSearch接口

IClassChainSearch是一个接口,它定义了在类链模式中搜索元素的方式,例如搜索按钮

public static $button = "**/XCUIElementTypeButton[%s == '%s']";

在AppTestCase中定义的默认值是label,所以每次调用clickOnButton时,前面的语句变为

public static $button = "**/XCUIElementTypeButton['label' == '%s']";

您可以使用以下语句重写它

$this->test->setClassChainSearch(IClassChainSearch::name);

OR

$this->test->setClassChainSearch(IClassChainSearch::value);

完整示例在此处

$this->test->clickOnButton('SIGN UP', 400);
$this->test->setLocatorStrategy("name");
$this->test->clickOnButton('button_name', 400);
$this->test->setLocatorStrategy("value");
$this->test->clickOnButton('button_value', 400);
  • 第一个clickOnButton点击标签为 'SIGN UP' 的按钮
  • 第二个clickOnButton点击名为 'button_name' 的按钮
  • 第三个clickOnButton点击值为 'button_value' 的按钮

clickOnButton的第二个参数定义了执行操作前的毫秒数