Java java지도 시간 SPRING 기반 APPIUM 구성 애플리케이션에 대한 자세한 소개

SPRING 기반 APPIUM 구성 애플리케이션에 대한 자세한 소개

Mar 19, 2017 am 11:16 AM

이 기사에서는 주로 Spring프레임워크를 사용하여 Appium의 드라이버 호출을 최적화하고 코드에 기록된 다수의 구성 매개변수를 구성 파일에 정의하는 방법에 대해 설명합니다. AndroidDriver 또는 IOSDriver를 호출할지 제어합니다.

Spring 환경을 직접 구축해 보세요.

다음 사용 사례는 spring4.3, appium java client 4.1.2, selenium 3.0.1을 기반으로 합니다.

먼저 드라이버를 작성하고 동일한 Bean 속성을 정의합니다. AndroidDriver를 생성할 때 IOSDriver 관련:

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를 생성하여 Driver

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();
    }

}
로그인 후 복사

를 초기화하고 닫습니다. 그런 다음 Spring 구성 파일을 작성합니다.

<?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>
로그인 후 복사

여기에는 구성 파일에서 Android 및 IOS 관련 구성을 저장하는 데 사용되는 두 개의 .properties를 정의했습니다.

세 번째 구성 파일이 전달됩니다.

<property name="capabilityList" ref ="# {baseconfig.environment}"></property>

로드할 구성 파일을 가져오는 방법

.properties 구성 파일은 다음과 같습니다.

android.properties 여기서는 WeChat

#APPium Android Driver
platformName:Android
deviceName:HUAWEIP8
platformVersion:6.0
# wechat
appPackage:com.tencent.mm
appActivity:.ui.LauncherUI
로그인 후 복사

ios.properties.app 호출을 시뮬레이션합니다.

#APPium IOS Driver
platformName:iOS
deviceName:iPhone Simulator
automationName:XCUITest
platformVersion:10.2
app:/X/X/X.app
로그인 후 복사

baseconfig.properties

environment:androidCapabilityList
# Driver url
url:http://127.0.0.1:4723/wd/hub
로그인 후 복사

경로를 직접 구성하세요. WeChat을 호출할 수 있는지 확인하기 위한 테스트 클래스 작성

package test;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

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

public class TestDemo {

    static ApplicationContext ctx;
    static AndroidDriver&lt;MobileElement&gt; driver;
    static DriverAdaptor driverAdaptor;

    @Before
    public void before() throws Exception {
        ctx = new ClassPathXmlApplicationContext(&quot;spring.xml&quot;);
        driverAdaptor = ctx.getBean(&quot;driverAdaptor&quot;, DriverAdaptor.class);
        driverAdaptor.initAndroidDriverByConfigFile();
    }

    @After
    public void after() throws Exception {
        if (driverAdaptor != null)
            driverAdaptor.quitAndoridSession();
    }

    @Test
    public void test1() throws InterruptedException {
        Thread.sleep(5000);
    }

}
로그인 후 복사

테스트 메서드는 지연만 기록합니다. WeChat을 호출할 수 있으면 프로세스가 성공한 것입니다.

위 내용은 SPRING 기반 APPIUM 구성 애플리케이션에 대한 자세한 소개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Java의 클래스로드 메커니즘은 다른 클래스 로더 및 대표 모델을 포함하여 어떻게 작동합니까? Java의 클래스로드 메커니즘은 다른 클래스 로더 및 대표 모델을 포함하여 어떻게 작동합니까? Mar 17, 2025 pm 05:35 PM

Java의 클래스로드 메커니즘은 다른 클래스 로더 및 대표 모델을 포함하여 어떻게 작동합니까?

2025 년 상위 4 개의 JavaScript 프레임 워크 : React, Angular, Vue, Svelte 2025 년 상위 4 개의 JavaScript 프레임 워크 : React, Angular, Vue, Svelte Mar 07, 2025 pm 06:09 PM

2025 년 상위 4 개의 JavaScript 프레임 워크 : React, Angular, Vue, Svelte

고급 Java 프로젝트 관리, 구축 자동화 및 종속성 해상도에 Maven 또는 Gradle을 어떻게 사용합니까? 고급 Java 프로젝트 관리, 구축 자동화 및 종속성 해상도에 Maven 또는 Gradle을 어떻게 사용합니까? Mar 17, 2025 pm 05:46 PM

고급 Java 프로젝트 관리, 구축 자동화 및 종속성 해상도에 Maven 또는 Gradle을 어떻게 사용합니까?

Java에서 기능 프로그래밍 기술을 어떻게 구현할 수 있습니까? Java에서 기능 프로그래밍 기술을 어떻게 구현할 수 있습니까? Mar 11, 2025 pm 05:51 PM

Java에서 기능 프로그래밍 기술을 어떻게 구현할 수 있습니까?

Node.js 20 : 주요 성능 향상 및 새로운 기능 Node.js 20 : 주요 성능 향상 및 새로운 기능 Mar 07, 2025 pm 06:12 PM

Node.js 20 : 주요 성능 향상 및 새로운 기능

빙산 : 데이터 호수 테이블의 미래 빙산 : 데이터 호수 테이블의 미래 Mar 07, 2025 pm 06:31 PM

빙산 : 데이터 호수 테이블의 미래

캐싱 및 게으른 하중과 같은 고급 기능을 사용하여 객체 관계 매핑에 JPA (Java Persistence API)를 어떻게 사용하려면 어떻게해야합니까? 캐싱 및 게으른 하중과 같은 고급 기능을 사용하여 객체 관계 매핑에 JPA (Java Persistence API)를 어떻게 사용하려면 어떻게해야합니까? Mar 17, 2025 pm 05:43 PM

캐싱 및 게으른 하중과 같은 고급 기능을 사용하여 객체 관계 매핑에 JPA (Java Persistence API)를 어떻게 사용하려면 어떻게해야합니까?

카페인 또는 구아바 캐시와 같은 라이브러리를 사용하여 자바 애플리케이션에서 다단계 캐싱을 구현하려면 어떻게해야합니까? 카페인 또는 구아바 캐시와 같은 라이브러리를 사용하여 자바 애플리케이션에서 다단계 캐싱을 구현하려면 어떻게해야합니까? Mar 17, 2025 pm 05:44 PM

카페인 또는 구아바 캐시와 같은 라이브러리를 사용하여 자바 애플리케이션에서 다단계 캐싱을 구현하려면 어떻게해야합니까?

See all articles