是否有可能在远程计算机上运行Appium,并且设备也连接在同一台远程计算机上,并从本地计算机运行测试脚本?
下面的代码在使用本地appium服务器的本地计算机上运行良好。 请帮助我任何one.bcaz我是appium的新手。
package com.appiumproj.test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
public class Appium {
AppiumDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.VERSION, "5.0.2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"ZX1D62FPVQ");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculatord");
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCal(){
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
WebElement results=driver.findElement(By.className("android.widget.EditText"));
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
System.out.println("Inside Test Function");
terClass
public void teardown(){
driver.closeApp();
}
}
答案 0 :(得分:0)
在端口4723上的远程计算机上启动appium服务器。然后更改行
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
到
driver = new AndroidDriver(new URL("http://IP OF THE REMOTE MACHINE :4723/wd/hub"), capabilities);