gpt4 book ai didi

android - 如何使用studio在android中设置环境变量以激活uiautomatorviewer

转载 作者:行者123 更新时间:2023-11-28 21:21:03 25 4
gpt4 key购买 nike

任何人都可以帮助我设置环境以集成 Appium 工具进行自动化测试。我一直停留在 uiautomatorviewer

我已经设置了 Android Studio 并安装了 JDK。

最佳答案

设置环境变量:

  1. Android SDK 路径:C:\Users\user_name\AppData\Local\Android\Sdk

  2. 在环境变量中设置ANDROID_HOME:并从上面设置SDK的路径

  3. 在 Android SDK 文件夹中,您需要将三个特定文件夹添加到 Path 变量中。这些文件夹是 –

    C:\Users\用户名\AppData\Local\Android\Sdk\platform-toolsC:\Users\用户名\AppData\Local\Android\Sdk\toolsC:\Users\用户名\AppData\Local\Android\Sdk\tools\bin

    %ANDROID_HOME%\平台工具ANDROID_HOME%\工具%ANDROID_HOME%\tools\bin

  4. 设置 PATH 变量:

    您应该已经添加了所有 3 个文件夹位置 – ;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;%ANDROID_HOME%\tools\bin

  5. 要验证所有 Android 环境变量是否已正确设置,请打开命令提示符并运行此命令:sdkmanager – -list(请注意,2 个连字符之间不应有空格)。

  6. 您还可以在命令提示符下运行此命令:uiautomatorviewer。这将打开 UI Automator 查看器窗口。

  7. 在环境变量中设置 JAVA_HOME:

    C:\Program Files\Java\jdk1.8.0_131

  8. 将此变量添加到 PATH 变量,如下所示:

    ;%JAVA_HOME%\bin;

要完成自动化设置,请按照以下说明操作:

使用 uiautomatorviewer 捕获屏幕。

Steps for Appium Setup:

1. Install android studio
2 SDK
2. Appium jar files selenium
3. Appium java client jar
4. Java selenium library
5. Appium server
6. Java
7 install pdanet in both system and mobile device co connectivity
8 gson jar files





**steps**
Open android Studio

Create new project

Create new basic activity

Copy java client jar file and paste in the app/lib folder

select all jar copied files in the lib folder then right click and click on "Add as library".

select build.gradle then rebuild project

commit jUnit and paste following code beneath of it
testCompile 'org.assertj:assertj-core:2.0.0'
testCompile 'org.testng:testng:6.9.10'

sync the code

Right click on Package Name the create a new class


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class WaitTest {
RemoteWebDriver driver;

@BeforeMethod
public void setUp() throws MalformedURLException {
// Created object of DesiredCapabilities class.
DesiredCapabilities capabilities = new DesiredCapabilities();

// Set android deviceName desired capability. Set your device name.

capabilities.setCapability("deviceName", "4200174ad22b7200");

// Set BROWSER_NAME desired capability. It's Android in our case here.
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

// Set android VERSION desired capability. Set your mobile device's OS version.

capabilities.setCapability(CapabilityType.VERSION, "5.1.1");

// Set android platformName desired capability. It's Android in our case here.
capabilities.setCapability("platformName", "Android");

// Set android appPackage desired capability. It is
// com.android.calculator2 for calculator application.
// Set your application's appPackage if you are using any other app.
capabilities.setCapability("appPackage", "in.dishtv.svctechnician");

// Set android appActivity desired capability. It is
// com.android.calculator2.Calculator for calculator application.
// Set your application's appPackage if you are using any other app.
capabilities.setCapability("appActivity", "in.dishtv.svctechnician.activity.MyActivity");

// Created object of RemoteWebDriver will all set capabilities.
// Set appium server address and port number in URL string.
// It will launch calculator app in android device.
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
//driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

}

@org.junit.Test
public void LoginTest1() {
try {
setUp();
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.findElement(By.id("userNameEdittext")).sendKeys("james");

driver.findElement(By.id("passwordEdittext")).sendKeys("bond");

driver.findElement(By.id("submitButton")).click();


driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@AfterMethod
public void End() {
driver.quit();
}
}


Do not import Selenium jar (because of it's too long size) use Gradle link from Below:


**compile group: 'org.seleniumhq.selenium', name: 'selenium-server-standalone', version: '2.53.0'**



Start Appium server

concect device


run tests in the android studio

关于android - 如何使用studio在android中设置环境变量以激活uiautomatorviewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51667574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com