Selendroid server 2种启动方式

本文介绍如何使用Selendroid进行移动应用自动化测试,包括配置Selendroid服务器、定义测试能力参数、执行基本的UI交互操作及断言验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 在执行test前, 通过命令启动。

java -jar E:\maven\SeleGrid2\selendroid-standalone-0.16.0-with-dependencies.jar -app "you uat path\SS_UAT.apk" -serverStartTimeout  100000 -serverStartRetries 3


打开http://localhost:4444/wd/hub/status

{"value":{"os":{"name":"Windows 7","arch":"amd64","version":"6.1"},
"build":{"browserName":"selendroid","version":"0.16.0"},
"supportedDevices":[{"emulator":true,"screenSize":"(800, 1280)","avdName":"11","platformVersion":"19","apiTargetType":"android"}],
"supportedApps":[{"mainActivity":"com.singtel.mystorage.MainActivity","appId":"com.singtel.mystorage:2.0.22.697",
"basePackage":"com.singtel.mystorage"},
{"mainActivity":"io.selendroid.androiddriver.WebViewActivity","appId":"io.selendroid.androiddriver:0.16.0","basePackage":"io.selendroid.androiddriver"}]},"status":0}

实现代码:

@Test
    public void test03() throws Exception{
        
        SelendroidCapabilities capa = new SelendroidCapabilities("com.singtel.mystorage:2.0.22.697");
        //capa.setLaunchActivity("com.singtel.mystorage.MainActivity");
        capa.setPlatformVersion(DeviceTargetPlatform.ANDROID19);
    
        capa.setEmulator(true);
        
        SelendroidDriver sd = new SelendroidDriver(capa);
        
        System.out.println(sd.getContextHandles()); //用于返回被测app是NATIVE_APP还是WEBVIEW,如果两者都有就是混合型App
        
        //查看元素,输入,登录等动作
        sd.quit();
        
    }


2. 通过代码

import junit.framework.Assert;
import io.selendroid.client.SelendroidDriver;
import io.selendroid.common.SelendroidCapabilities;
import io.selendroid.common.device.DeviceTargetPlatform;
import io.selendroid.standalone.SelendroidConfiguration;
import io.selendroid.standalone.SelendroidLauncher;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class NativeApp2 {
    
    private DesiredCapabilities seCap = null;
    private SelendroidConfiguration config = null;
    private SelendroidLauncher selendroidServer= null;
    private WebDriver wd = null;
    
    @BeforeTest
    public void setup(){
        if(selendroidServer != null){
            selendroidServer.stopSelendroid();
        }
        config = new SelendroidConfiguration();
        config.addSupportedApp("SS_UAT.apk"); //设置apk相对路径
        
        selendroidServer = new SelendroidLauncher(config);
        selendroidServer.launchSelendroid();
    }
    
    @Test
    public void test03() throws Exception{
         seCap = new SelendroidCapabilities("com.singtel.mystorage:2.0.22.697"); //设置appid值,需要和status的appid保持一致

        
    
        
        wd = new SelendroidDriver(seCap);
        
        WebElement inputField = wd.findElement(By.id("my_text_field"));
        inputField.sendKeys("Selendroid");
        
        Thread.sleep(3000);
        Assert.assertEquals("Selendroid", inputField.getText());
        
    }
    
    @AfterTest
    public void teardown(){
        if(selendroidServer != null){
            selendroidServer.stopSelendroid();
        }
    }
}

参考资料

https://github.com/selendroid/demoproject-selendroid/blob/master/src/main/java/io/selendroid/demo/SelendroidIntegrationTest.java#L45

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值