ホームページ Java &#&チュートリアル SPRING に基づく APPIUM 構成アプリケーションの詳細な紹介

SPRING に基づく APPIUM 構成アプリケーションの詳細な紹介

Mar 19, 2017 am 11:16 AM

この記事では主に、Springframeworkを使用してAppiumのDriver呼び出しを最適化し、コードに書かれた多数の設定パラメータを設定ファイルに定義し、またAndroidDriverを呼び出すか、または呼び出すかを柔軟に制御する方法について説明します。 IOSドライバー。

Spring環境はご自身で構築してください。

次の使用例は、spring4.3、appium Java クライアント 4.1.2、selenium 3.0.1 に基づいています

まず、ドライバーを作成し、AndroidDriver と IOSDriver の作成に関連するいくつかの Bean プロパティを定義します。次に、Driver

package test;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;

@Component
@Scope("prototype")
public class Driver {

    private List<ArrayList<String>> capabilityList;
    private DesiredCapabilities capabilities;
    private URL url;
    private AndroidDriver<MobileElement> androidDriver;
    private IOSDriver<MobileElement> iOSDriver;

    public List<ArrayList<String>> getCapabilityList() {
        return capabilityList;
    }

    public void setCapabilityList(List<ArrayList<String>> capabilityList) {
        this.capabilityList = capabilityList;
    }

    public DesiredCapabilities getCapabilities() {
        return capabilities;
    }

    public void setCapabilities(DesiredCapabilities capabilities) {
        this.capabilities = capabilities;
    }

    public URL getUrl() {
        return url;
    }

    public void setUrl(URL url) {
        this.url = url;
    }

    public AndroidDriver<MobileElement> getAndroidDriver() {
        return androidDriver;
    }

    public void setAndroidDriver(AndroidDriver<MobileElement> androidDriver) {
        this.androidDriver = androidDriver;
    }

    public IOSDriver<MobileElement> getiOSDriver() {
        return iOSDriver;
    }

    public void setiOSDriver(IOSDriver<MobileElement> iOSDriver) {
        this.iOSDriver = iOSDriver;
    }

}
ログイン後にコピー

を初期化して閉じるためのDriverAdaptorを作成します。次に、Spring構成ファイルを作成します:

package test;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;

@Component
public class DriverAdaptor {

    private AndroidDriver<MobileElement> androidDriver = null;
    private IOSDriver<MobileElement> iOSDriver = null;

    @Resource
    private Driver driver;

    public Driver getDriver() {
        return driver;
    }

    public void setDriver(Driver driver) {
        this.driver = driver;
    }

    @Resource
    ApplicationContext ctx;

    @Value("#{baseconfig.environment}")
    String environment;

    @SuppressWarnings("unchecked")
    public void initAndroidDriverByConfigFile() throws Exception {
        for (ArrayList<String> arg : (List<ArrayList<String>>) ctx.getBean(environment)) {
            ctx.getBean("capabilities", DesiredCapabilities.class).setCapability(arg.get(0), arg.get(1));
        }
        androidDriver = new AndroidDriver<>(driver.getUrl(), driver.getCapabilities());
        driver.setAndroidDriver(androidDriver);
    }

    public void quitAndoridSession() {
        if (androidDriver != null)
            androidDriver.quit();
    }

    @SuppressWarnings("unchecked")
    public void initIOSDriverByConfigFile() throws Exception {
        for (ArrayList<String> arg : (List<ArrayList<String>>) ctx.getBean(environment)) {
            ctx.getBean("capabilities", DesiredCapabilities.class).setCapability(arg.get(0), arg.get(1));
        }
        iOSDriver = new IOSDriver<>(driver.getUrl(), driver.getCapabilities());
        driver.setiOSDriver(iOSDriver);
    }

    public void quitIOSService() {
        if (iOSDriver != null)
            iOSDriver.quit();
    }

}
ログイン後にコピー

この構成ファイルでは、AndroidとIOSの関連構成を保存するために使用される2つの.propertiesを定義します

。 3 番目の構成ファイルは、


を使用して、ロードする構成ファイルを取得します

.properties 構成ファイルは次のとおりです:

android.properties ここでは、WeChat

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">

    <!-- 组件扫描 -->
    <context:component-scan base-package="test"></context:component-scan>
    <!-- aspect -->
    <aop:aspectj-autoproxy proxy-target-class="false" />

    <!-- 定义配置文件properties -->
    <util:properties id="android" location="classpath:android.properties" />
    <util:properties id="ios" location="classpath:ios.properties" />
    <util:properties id="baseconfig" location="classpath:baseconfig.properties" />
    <!-- Android -->
    <util:list id="androidCapabilityList">
        <list>
            <value>platformName</value>
            <value>#{android.platformName}</value>
        </list>
        <list>
            <value>deviceName</value>
            <value>#{android.deviceName}</value>
        </list>
        <list>
            <value>platformVersion</value>
            <value>#{android.platformVersion}</value>
        </list>
        <list>
            <value>appPackage</value>
            <value>#{android.appPackage}</value>
        </list>
        <list>
            <value>appActivity</value>
            <value>#{android.appActivity}</value>
        </list>
    </util:list>
    <!-- IOS -->
    <util:list id="iOScapabilityList">
        <list>
            <value>platformName</value>
            <value>#{ios.platformName}</value>
        </list>
        <list>
            <value>deviceName</value>
            <value>#{ios.deviceName}</value>
        </list>
        <list>
            <value>automationName</value>
            <value>#{ios.automationName}</value>
        </list>
        <list>
            <value>platformVersion</value>
            <value>#{ios.platformVersion}</value>
        </list>
        <list>
            <value>app</value>
            <value>#{ios.app}</value>
        </list>
    </util:list>
    <!-- appium driver -->
    <bean id="url" class="java.net.URL">
        <constructor-arg index="0" value="#{baseconfig.url}"></constructor-arg>
    </bean>
    <bean id="capabilities" class="org.openqa.selenium.remote.DesiredCapabilities"></bean>
    <bean id="driver" class="test.Driver">
        <property name="capabilityList" ref="#{baseconfig.environment}"></property>
        <property name="capabilities" ref="capabilities"></property>
        <property name="url" ref="url"></property>
    </bean>
</beans>
ログイン後にコピー

ios.properties .app の呼び出しをシミュレートします。パスは自分で設定してください

#APPium Android Driver
platformName:Android
deviceName:HUAWEIP8
platformVersion:6.0
# wechat
appPackage:com.tencent.mm
appActivity:.ui.LauncherUI
ログイン後にコピー

baseconfig.properties

#APPium IOS Driver
platformName:iOS
deviceName:iPhone Simulator
automationName:XCUITest
platformVersion:10.2
app:/X/X/X.app
ログイン後にコピー

最後に、テスト クラスを作成して、それが機能するかどうかを確認します。呼び出し可能

environment:androidCapabilityList
# Driver url
url:http://127.0.0.1:4723/wd/hub
ログイン後にコピー

テストメソッドには遅延のみが含まれています。WeChat を呼び出すことができれば、プロセスは成功したことを意味します。

以上がSPRING に基づく APPIUM 構成アプリケーションの詳細な紹介の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

カフェインやグアバキャッシュなどのライブラリを使用して、Javaアプリケーションにマルチレベルキャッシュを実装するにはどうすればよいですか? カフェインやグアバキャッシュなどのライブラリを使用して、Javaアプリケーションにマルチレベルキャッシュを実装するにはどうすればよいですか? Mar 17, 2025 pm 05:44 PM

この記事では、カフェインとグアバキャッシュを使用してJavaでマルチレベルキャッシュを実装してアプリケーションのパフォーマンスを向上させています。セットアップ、統合、パフォーマンスの利点をカバーし、構成と立ち退きポリシー管理Best Pra

Javaで機能的なプログラミング技術を実装するにはどうすればよいですか? Javaで機能的なプログラミング技術を実装するにはどうすればよいですか? Mar 11, 2025 pm 05:51 PM

この記事では、Lambda式、Streams API、メソッド参照、およびオプションを使用して、機能プログラミングをJavaに統合することを調べます。 それは、簡潔さと不変性を通じてコードの読みやすさと保守性の改善などの利点を強調しています

Javaのクラスロードメカニズムは、さまざまなクラスローダーやその委任モデルを含むどのように機能しますか? Javaのクラスロードメカニズムは、さまざまなクラスローダーやその委任モデルを含むどのように機能しますか? Mar 17, 2025 pm 05:35 PM

Javaのクラスロードには、ブートストラップ、拡張機能、およびアプリケーションクラスローダーを備えた階層システムを使用して、クラスの読み込み、リンク、および初期化が含まれます。親の委任モデルは、コアクラスが最初にロードされ、カスタムクラスのLOAに影響を与えることを保証します

キャッシュや怠zyなロードなどの高度な機能を備えたオブジェクトリレーショナルマッピングにJPA(Java Persistence API)を使用するにはどうすればよいですか? キャッシュや怠zyなロードなどの高度な機能を備えたオブジェクトリレーショナルマッピングにJPA(Java Persistence API)を使用するにはどうすればよいですか? Mar 17, 2025 pm 05:43 PM

この記事では、キャッシュや怠zyなロードなどの高度な機能を備えたオブジェクトリレーショナルマッピングにJPAを使用することについて説明します。潜在的な落とし穴を強調しながら、パフォーマンスを最適化するためのセットアップ、エンティティマッピング、およびベストプラクティスをカバーしています。[159文字]

高度なJavaプロジェクト管理、自動化の構築、依存関係の解像度にMavenまたはGradleを使用するにはどうすればよいですか? 高度なJavaプロジェクト管理、自動化の構築、依存関係の解像度にMavenまたはGradleを使用するにはどうすればよいですか? Mar 17, 2025 pm 05:46 PM

この記事では、Javaプロジェクト管理、自動化の構築、依存関係の解像度にMavenとGradleを使用して、アプローチと最適化戦略を比較して説明します。

非ブロッキングI/OにJavaのNIO(新しい入出力)APIを使用するにはどうすればよいですか? 非ブロッキングI/OにJavaのNIO(新しい入出力)APIを使用するにはどうすればよいですか? Mar 11, 2025 pm 05:51 PM

この記事では、単一のスレッドで複数の接続を効率的に処理するためにセレクターとチャネルを使用して、非ブロッキングI/O用のJavaのNIO APIについて説明します。 プロセス、利点(スケーラビリティ、パフォーマンス)、および潜在的な落とし穴(複雑さ、

適切なバージョン化と依存関係管理を備えたカスタムJavaライブラリ(JARファイル)を作成および使用するにはどうすればよいですか? 適切なバージョン化と依存関係管理を備えたカスタムJavaライブラリ(JARファイル)を作成および使用するにはどうすればよいですか? Mar 17, 2025 pm 05:45 PM

この記事では、MavenやGradleなどのツールを使用して、適切なバージョン化と依存関係管理を使用して、カスタムJavaライブラリ(JARファイル)の作成と使用について説明します。

ネットワーク通信にJavaのソケットAPIを使用するにはどうすればよいですか? ネットワーク通信にJavaのソケットAPIを使用するにはどうすればよいですか? Mar 11, 2025 pm 05:53 PM

この記事では、ネットワーク通信のためのJavaのソケットAPI、クライアントサーバーのセットアップ、データ処理、リソース管理、エラー処理、セキュリティなどの重要な考慮事項をカバーしています。 また、パフォーマンスの最適化手法も調査します

See all articles