如何在远程计算机上运行appium脚本?

Yosuva A

我有2台台式机,其中Appium脚本保存在1号机中,而Appium安装在2号机中,并且android设备也连接在2号机中。现在,我想从1号机中获取脚本并在连接的设备中执行该脚本。机器2.如何实现这一目标。请建议我。下面的代码我能够运行同一台机器。我想在连接到另一台机器上的android设备上运行。两个机器的IP段是同一段。

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();
}
}
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"); // This is package name of your app (you can get it from apk info app
   capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
   //Create AndroidDriver instance and connect to the Appium server.
   //It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities

   driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void testCal(){

    //locate the Text on the calculator by using By.name()
   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();
    //locate the edit box of the calculator by using By.className()
    WebElement results=driver.findElement(By.className("android.widget.EditText"));
    //Check the calculated value on the edit box
    assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";
/*
	System.out.println("Inside Test Function");
	driver.findElement(By.partialLinkText("More")).click();
	driver.findElement(By.xpath("//EditText[@text='Email Address']")).sendKeys("[email protected]");
	driver.findElement(By.xpath("//LinearLayout/EditText[2]")).sendKeys("Testerpwd");
	driver.findElement(By.xpath("//CheckBox")).click();
	driver.findElement(By.xpath("//Button[@text='Login']")).click();

	WebDriverWait wait = new WebDriverWait(driver,80);
	wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//Button[@text='Logout']"))); 
	driver.findElement(By.xpath("//Button[@text='Logout']")).click(); 
*/
}
@AfterClass
public void teardown(){
   
    //close the app
    driver.closeApp();
}
}

库什布

在计算机2上运行的Appium实例上提供确切的IP地址。默认情况下,它是127.0.0.1,将其删除,并在Appium设置中显式提供其自己的IP地址。这将起作用。让我知道是否。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在远程计算机上运行PowerShell脚本?

来自分类Dev

如何在远程计算机上执行AutoIt脚本

来自分类Dev

如何在远程计算机上并行运行脚本?

来自分类Dev

如何在远程计算机上运行复杂的awk脚本?

来自分类Dev

如何在远程计算机上延迟运行脚本

来自分类Dev

Jenkins:如何在远程计算机上运行 exe

来自分类Dev

在远程Windows计算机上运行bash脚本

来自分类Dev

在远程计算机上运行QTP脚本(Windows 7)

来自分类Dev

在远程计算机上运行本地python脚本

来自分类Dev

在远程计算机上运行.reg文件的Powershell脚本

来自分类Dev

linux +在远程计算机上运行脚本

来自分类Dev

在远程计算机上运行Selenium脚本

来自分类Dev

在本地和远程计算机上运行的Shell脚本

来自分类Dev

如何将参数传递到Powershell脚本并在远程计算机上运行

来自分类Dev

如何将参数传递给Powershell脚本并在远程计算机上运行

来自分类Dev

如何允许本地计算机上的jenkins运行远程python测试脚本

来自分类Dev

如何在远程计算机上执行本地脚本并包含参数?

来自分类Dev

如何在远程计算机上异步执行bash脚本

来自分类Dev

如何在远程计算机上运行量角器测试

来自分类Dev

如何在远程计算机上运行复杂的awk命令

来自分类Dev

使用ssh,如何在不退出的情况下在远程计算机上运行命令?

来自分类Dev

如何在所有局域网计算机上远程运行“ winrm quickconfig”

来自分类Dev

如何在远程计算机上运行本地bat文件

来自分类Dev

如何在远程计算机上运行Get-ChildItem命令

来自分类Dev

如何在单个时间点在不同的远程计算机上运行单个命令

来自分类Dev

如何从本地计算机执行存储在远程计算机上的Shell脚本?

来自分类Dev

如何使远程计算机在远程计算机本身上运行PowerShell脚本?

来自分类Dev

如何使用 PowerShell 脚本在远程计算机上运行另一个 PowerShell 脚本

来自分类Dev

如何在无法安装所需软件包的计算机上运行python脚本?

Related 相关文章

  1. 1

    如何在远程计算机上运行PowerShell脚本?

  2. 2

    如何在远程计算机上执行AutoIt脚本

  3. 3

    如何在远程计算机上并行运行脚本?

  4. 4

    如何在远程计算机上运行复杂的awk脚本?

  5. 5

    如何在远程计算机上延迟运行脚本

  6. 6

    Jenkins:如何在远程计算机上运行 exe

  7. 7

    在远程Windows计算机上运行bash脚本

  8. 8

    在远程计算机上运行QTP脚本(Windows 7)

  9. 9

    在远程计算机上运行本地python脚本

  10. 10

    在远程计算机上运行.reg文件的Powershell脚本

  11. 11

    linux +在远程计算机上运行脚本

  12. 12

    在远程计算机上运行Selenium脚本

  13. 13

    在本地和远程计算机上运行的Shell脚本

  14. 14

    如何将参数传递到Powershell脚本并在远程计算机上运行

  15. 15

    如何将参数传递给Powershell脚本并在远程计算机上运行

  16. 16

    如何允许本地计算机上的jenkins运行远程python测试脚本

  17. 17

    如何在远程计算机上执行本地脚本并包含参数?

  18. 18

    如何在远程计算机上异步执行bash脚本

  19. 19

    如何在远程计算机上运行量角器测试

  20. 20

    如何在远程计算机上运行复杂的awk命令

  21. 21

    使用ssh,如何在不退出的情况下在远程计算机上运行命令?

  22. 22

    如何在所有局域网计算机上远程运行“ winrm quickconfig”

  23. 23

    如何在远程计算机上运行本地bat文件

  24. 24

    如何在远程计算机上运行Get-ChildItem命令

  25. 25

    如何在单个时间点在不同的远程计算机上运行单个命令

  26. 26

    如何从本地计算机执行存储在远程计算机上的Shell脚本?

  27. 27

    如何使远程计算机在远程计算机本身上运行PowerShell脚本?

  28. 28

    如何使用 PowerShell 脚本在远程计算机上运行另一个 PowerShell 脚本

  29. 29

    如何在无法安装所需软件包的计算机上运行python脚本?

热门标签

归档