第十期_自动化测试平台_20190908

架构

STF

环境

MacBook-Pro-3:_bufferutil@1.3.0@bufferutil seveniruby$ npm version
{ bufferutil: '1.3.0',
  npm: '6.4.1',
  ares: '1.10.1-DEV',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.33.0',
  node: '8.15.0',
  openssl: '1.0.2q',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.2.414.75',
  zlib: '1.2.11' }

官方说明必须使用nodejs8

Node.js 8.x required

install

brew install rethinkdb graphicsmagick zeromq protobuf yasm pkg-config
npm install -g stf
#cnpm install -g stf

quick start

nohup rethinkdb &
stf local --public-ip 0.0.0.0 

STF API

STF调度脚本

#!/usr/bin/env bash

STF_TOKEN=dc9ebbcc9eb94994baa1e346fe23b3c32d59629bba0b4a219c0c67a96dfb3989
#STF_URL=http://39.105.132.200:7100
STF_URL=http://127.0.0.1:7100
DEVICE_SERIAL="emulator-5554"

function add_device() {
    response=$(curl -X POST -H "Content-Type: application/json" \\
        -H "Authorization: Bearer $STF_TOKEN" \\
        --data "{\\"serial\\": \\"$DEVICE_SERIAL\\"}" $STF_URL/api/v1/user/devices)

    success=$(echo "$response" | jq .success | tr -d '"')
    description=$(echo "$response" | jq .description | tr -d '"')

    if [ "$success" != "true" ]; then
        echo "Failed because $description"
        echo exit 1
    fi

    echo "Device $DEVICE_SERIAL added successfully"
}

function remote_connect() {
    response=$(curl -X POST \\
        -H "Authorization: Bearer $STF_TOKEN" \\
        $STF_URL/api/v1/user/devices/$DEVICE_SERIAL/remoteConnect)

    success=$(echo "$response" | jq .success | tr -d '"')
    description=$(echo "$response" | jq .description | tr -d '"')

    if [ "$success" != "true" ]; then
        echo "Failed because $description"
        echo exit 1
    fi
    remote_connect_url=$(echo "$response" | jq .remoteConnectUrl | tr -d '"')

    adb connect $remote_connect_url

    echo "Device $DEVICE_SERIAL remote connected successfully"
}

function remove_device() {
    adb disconnect $remote_connect_url
    response=$(curl -X DELETE \\
        -H "Authorization: Bearer $STF_TOKEN" \\
        $STF_URL/api/v1/user/devices/$DEVICE_SERIAL)

    success=$(echo "$response" | jq .success | tr -d '"')
    description=$(echo "$response" | jq .description | tr -d '"')

    if [ "$success" != "true" ]; then
        echo "Failed because $description"
        echo exit 1
    fi

    echo "Device $DEVICE_SERIAL removed successfully"
}

function every_device() {
    #获得可用设备列表
    devices=$(curl -H "Authorization: Bearer $STF_TOKEN" $STF_URL/api/v1/devices | jq -r '.devices[] | select(.present==true)|.serial ')
    for DEVICE_SERIAL in $devices; do
    {
        add_device
        remote_connect
        sleep 2
        remote_device=$remote_connect_url
        eval $1
        adb disconnect $remote_device
        sleep 2
        remove_device
    } &
    done
}

示例

 . /Users/seveniruby/temp/stf/stf.sh
every_device 'java -jar ~/temp/appcrawlppcrawler-2.4.0-jar-with-dependencies.jar  -c ~/temp/appcrawler/xueqiu_demo_10.yaml --capability "udid=${remote_device},systemPort=1${remote_device#*:}" '

作业1

公网开放地址: http://39.105.132.200:7100/auth/mock/

Selenium Grid

java -jar selenium-server-standalone-2.44.0.jar -role hub
java -jar selenium-server-standalone-2.44.0.jar -role node  -hub http://localhost:4444/grid/register
appium --nodeconfig /path/to/nodeconfig.json

Jenkins自动调度

课后作业2

  • 使用STF 管理3台(真机+模拟器组合),把设备列表贴上来
  • 并行运行测试用例,(appium用例、 appcrawler 、maxim都可以)把多设备的并行运行的截图贴上来