日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

appium(3)-Running Tests

發(fā)布時(shí)間:2025/4/14 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 appium(3)-Running Tests 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Running Tests

Preparing your app for test (iOS)

Test apps run on the simulator have to be compiled specifically for the simulator, for example by executing the following command in the Xcode project:

> xcodebuild -sdk iphonesimulator6.0//創(chuàng)建一個(gè)文件夾,存放.app文件

This creates a build/Release-iphonesimulator directory in your Xcode project that contains the .app package that you’ll need to communicate with the Appium server.

If you want, you can zip up the .app directory into a .zip file! Appium will unpack it for you. Nice if you’re not using Appium locally.

Preparing your app for test (Android)

Nothing in particular needs to be done to run your .apk using Appium. If you want to zip it up, you can.//沒(méi)啥特別的。

?

Running your test app with Appium (iOS)

The best way to see what to do currently is to look at the example tests:

Node.js | Python | PHP | Ruby | Java

Basically, first make sure Appium is running:

node .

Then script your WebDriver test, sending in the following desired capabilities:

1 # python 2 { 3 'platformName': 'iOS', 4 'platformVersion': '7.1', 5 'deviceName': 'iPhone Simulator', 6 'app': myApp 7 }

?

1 // java 2 DesiredCapabilities capabilities = new DesiredCapabilities(); 3 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS"); 4 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1"); 5 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); 6 capabilities.setCapability(MobileCapabilityType.APP, myApp);

?

In this set of capabilities, myApp must be either://myApp參數(shù)必須滿足下面條件

  • A local absolute path to your simulator-compiled .app directory or .zip
  • A url of a zip file containing your .app package
  • A path to one of the sample app relative to the appium install root

Using your WebDriver library of choice, set the remote session to use these capabilities and connect to the server running at port 4723 of localhost (or whatever host and port you specified when you started Appium). You should be all set now!

Running your test app with Appium (Android)

First, make sure you have one and only one Android emulator or device connected. If you run adb devices, for example, you should see one device connected. This is the device Appium will use for tests. Of course, to have a device connected, you’ll need to have made an Android AVD (see system setup (Windows, Mac, or Linux) for more information). If the Android SDK tools are on your path, you can simply run://保證只有一個(gè)安卓仿真器或者設(shè)備取得連接。

emulator -avd

And wait for the android emulator to finish launching. Sometimes, for various reasons, adb gets stuck. If it’s not showing any connected devices or otherwise failing, you can restart it by running://有時(shí)候虛擬機(jī)會(huì)無(wú)法取得連接,需要反復(fù)重啟幾次

adb kill-server && adb devices

Now, make sure Appium is running:

node .

There are several ways to start an Appium application (it works exactly the same as when the application is started via adb):

  • apk or zip only, the default activity will be launched ('app’ capability)
  • apk + activity ('app’ + 'appActivity’ capabilities)
  • apk + activity + intent ('app’ + 'appActivity’ + 'appIntent’ capabilities)

Activities may be specified in the following way:

  • absolute (e.g. appActivity: 'com.helloworld.SayHello’).
  • relative to appPackage (e.g. appPackage: 'com.helloworld’, appActivity=’.SayHello’)

If the 'appWaitPackage’ and 'appWaitActivity’ caps are specified, Appium automatically spins until those activities are launched. You may specify multiple wait activities for instance:

  • appActivity: 'com.splash.SplashScreen’
  • appPackage: 'com.splash’ appActivity: ’.SplashScreen’
  • appPackage: 'com.splash’ appActivity: ’.SplashScreen,.LandingPage,com.why.GoThere’

If you are not sure what activity are configured in your apk, you can proceed in one of the following ways://查看activity的方法

  • Mac/Linux: 'adb shell dumpsys window windows | grep mFocusedApp’
  • In the Ruby console: 'adb shell dumpsys window windows`.each_line.grep(/mFocusedApp/).first.strip’
  • In Windows terminal run 'adb shell dumpsys window windows’ and manually look for the mFocusedApp line.

Then script your WebDriver test, sending in the following desired capabilities:

1 # python 2 { 3 'platformName': 'Android', 4 'platformVersion': '4.4', 5 'deviceName': 'Android Emulator', 6 'app': myApp 7 }

?

1 // java 2 DesiredCapabilities capabilities = new DesiredCapabilities(); 3 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); 4 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4"); 5 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); 6 capabilities.setCapability(MobileCapabilityType.APP, myApp); ?

In this set of capabilities, myApp must be either://myApp參數(shù)必須滿足下面條件

  • A local absolute path to your .apk or a .zip of it//絕對(duì)路徑
  • A url of a zip file containing your .apk//url地址
  • A path to one of the sample app relative to the appium install root//相對(duì)于appium安裝根目錄的相對(duì)路徑

Using your WebDriver library of choice, set the remote session to use these capabilities and connect to the server running at port 4723 of localhost (or whatever host and port you specified when you started Appium). You should be all set now!//使用自己選擇的編程語(yǔ)言,設(shè)置session需要的capability,連接到指定的ip和端口。

Running your test app with Appium (Android devices < 4.2, and hybrid tests)

Android devices before version 4.2 (API Level 17) do not have Google’s UiAutomator framework installed. This is what Appium uses to perform the automation behaviors on the device. For earlier devices or tests of hybrid (webview-based) apps, Appium comes bundled with another automation backend called Selendroid.//低版本的安卓系統(tǒng)內(nèi)沒(méi)有安裝谷歌的UiAutomator framework,所以沒(méi)法運(yùn)行appium。測(cè)試低版本設(shè)備和混合應(yīng)用需要使用Selendroid工具。

To use Selendroid, all that is required is to slightly change the set of desired capabilities mentioned above, by adding the automationName capability and specifying the Selendroid automation backend. It is usually the case that you also need to use a . before your activity name (e.g., .MainActivity instead of MainActivity for your appActivity capability).//appActivity的值需要加一個(gè)點(diǎn)。

# python {'automationName': 'Selendroid','platformName': 'Android','platformVersion': '2.3','deviceName': 'Android Emulator','app': myApp,'appPackage': 'com.mycompany.package','appActivity': '.MainActivity' } 1 // java 2 DesiredCapabilities capabilities = new DesiredCapabilities(); 3 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Selendroid"); 4 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); 5 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "2.3"); 6 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); 7 capabilities.setCapability(MobileCapabilityType.APP, myApp); 8 capabilities.setCapability(MobileCapabilityType.APP_PACKAGE: "com.mycompany.package"); 9 capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY: ".MainActivity");

?

Now Appium will start up a Selendroid test session instead of the default test session. One of the downsides to using Selendroid is that its API differs sometimes significantly with Appium’s. Therefore we recommend you thoroughly read Selendroid’s documentation before writing your scripts for older devices or hybrid apps.

轉(zhuǎn)載于:https://www.cnblogs.com/superbaby11/p/6062277.html

總結(jié)

以上是生活随笔為你收集整理的appium(3)-Running Tests的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。