windows系统中实现对于appium的依赖搭建

  1. Node.js :Appium是基于Node.js的,因此需要安装Node.js。可以从Node.js官网下载并安装。

  2. Java Development Kit (JDK):用于Android应用的自动化测试,需要安装JDK。可以从Oracle官网下载并安装。

  3. Android SDK:进行Android应用的自动化测试时,需要配置Android SDK。可以通过安装Android Studio来获取SDK,或者单独下载SDK并配置环境变量。

  4. Appium Server :可以通过npm命令npm install -g appium来安装Appium Server,或者下载Appium Desktop应用。

  5. Appium Inspector:这是一个可选工具,用于检查应用元素,可以从Appium Desktop应用中访问。

  6. Appium-Python-Client (如果使用Python编写测试脚本):可以通过pip命令pip install Appium-Python-Client来安装。

  7. .NET Framework(对于某些Windows系统):在安装Node.js时可能会需要。

  8. 环境变量配置 :需要配置环境变量以确保命令行工具可以正确运行,例如配置ANDROID_HOME指向Android SDK的安装路径,以及将SDK的platform-toolsbuild-tools目录添加到系统的Path变量中。

  9. 模拟器或真机:进行测试时需要有Android模拟器或真机设备。

  10. appium-doctor (可选):这是一个工具,用于检查Appium运行所需的依赖和环境变量是否正确配置。可以通过npm命令npm install -g appium-doctor来安装。

方案一

powershell 复制代码
# 安装 Node.js
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
    Write-Output "开始安装 Node.js,从 Node.js 官网下载并安装"
}

# 安装 Java Development Kit (JDK)
if (-not (Test-Path "C:\Program Files\Java\jdk1.8.0_202")) {
    Write-Output "开始安装 JDK,从 Oracle 官网下载并安装"
}

# 安装 Android SDK
if (-not (Test-Path "C:\Android\Sdk")) {
    Write-Output "开始安装 Android SDK,通过安装 Android Studio 来获取或单独下载并配置环境变量"
}

# 安装 Appium Server
if (-not (Get-Command appium -ErrorAction SilentlyContinue)) {
    Write-Output "开始安装 Appium Server,使用 npm 命令 npm install -g appium"
}

# 安装 Appium Inspector(可选)
if (-not (Get-Command appium-inspector -ErrorAction SilentlyContinue)) {
    Write-Output "开始安装 Appium Inspector,从 Appium Desktop 应用中访问"
}

# 安装 Appium-Python-Client(如果使用 Python 编写测试脚本)
if (-not (Get-Command pip -ErrorAction SilentlyContinue)) {
    Write-Output "开始安装 Appium-Python-Client,使用 pip 命令 pip install Appium-Python-Client"
}

#.NET Framework(对于某些 Windows 系统)
Write-Output ".NET Framework(可能需要在安装 Node.js 时安装)"

# 环境变量配置
Write-Output "需要配置环境变量,如配置 ANDROID_HOME 指向 Android SDK 的安装路径,将 SDK 的 platform-tools 和 build-tools 目录添加到系统的 Path 变量中"

# 模拟器或真机
Write-Output "进行测试时需要有 Android 模拟器或真机设备"

# appium-doctor(可选)
if (-not (Get-Command appium-doctor -ErrorAction SilentlyContinue)) {
    Write-Output "开始安装 appium-doctor,使用 npm 命令 npm install -g appium-doctor"
}

Write-Output "所有依赖环境安装完成"

方案二

powershell 复制代码
# PowerShell脚本:安装Appium及其依赖环境

# 设置执行策略
Set-ExecutionPolicy Bypass -Scope Process -Force

# 定义变量
$nodeJsUrl = "https://nodejs.org/dist/v14.17.0/node-v14.17.0-x64.msi"
$nodeJsInstaller = "$env:TEMP\node-v14.17.0-x64.msi"
$jdkUrl = "https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.msi"
$jdkInstaller = "$env:TEMP\jdk-17_windows-x64_bin.msi"
$androidSdkUrl = "https://dl.google.com/android/repository/commandlinetools-win-7583922_latest.zip"
$androidSdkZip = "$env:TEMP\commandlinetools-win-7583922_latest.zip"
$androidSdkDir = "$env:LOCALAPPDATA\Android\Sdk"

# 安装Node.js
Write-Host "Downloading and installing Node.js..."
Invoke-WebRequest -Uri $nodeJsUrl -OutFile $nodeJsInstaller
Start-Process -FilePath msiexec.exe -Args "/i `"$nodeJsInstaller`" /quiet /norestart" -Wait
Remove-Item $nodeJsInstaller

# 安装JDK
Write-Host "Downloading and installing JDK..."
Invoke-WebRequest -Uri $jdkUrl -OutFile $jdkInstaller
Start-Process -FilePath msiexec.exe -Args "/i `"$jdkInstaller`" /quiet /norestart" -Wait
Remove-Item $jdkInstaller

# 安装Android SDK
Write-Host "Downloading and installing Android SDK..."
Invoke-WebRequest -Uri $androidSdkUrl -OutFile $androidSdkZip
Expand-Archive -Path $androidSdkZip -DestinationPath $androidSdkDir
Remove-Item $androidSdkZip

# 配置环境变量
Write-Host "Configuring environment variables..."
$env:Path += ";$androidSdkDir\platform-tools"
$env:Path += ";$androidSdkDir\tools\bin"
$env:ANDROID_HOME = $androidSdkDir
[Environment]::SetEnvironmentVariable("Path", $env:Path, [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("ANDROID_HOME", $androidSdkDir, [EnvironmentVariableTarget]::Machine)

# 安装Appium Server
Write-Host "Installing Appium Server..."
npm install -g appium

# 安装Appium-Python-Client(如果使用Python)
Write-Host "Installing Appium-Python-Client..."
pip install Appium-Python-Client

# 安装appium-doctor
Write-Host "Installing appium-doctor..."
npm install -g appium-doctor

Write-Host "Installation completed. Please restart your computer."

# 重启计算机(可选)
# Restart-Computer
相关推荐
非凡ghost34 分钟前
猫眼浏览器(Chrome内核增强版浏览器)官方便携版
前端·网络·chrome·windows·软件需求
熊文豪6 小时前
Windows安装RabbitMQ保姆级教程
windows·分布式·rabbitmq·安装rabbitmq
搬砖的小码农_Sky6 小时前
Windows操作系统上`ping`命令的用法详解
运维·网络·windows
Kiri霧13 小时前
Rust模式匹配详解
开发语言·windows·rust
程序设计实验室15 小时前
使用命令行删除 Windows 网络映射驱动器
windows
用户311879455921817 小时前
Windows 电脑安装 XTerminal 1.25.1 x64 版(带安装包下载关键词)
windows
Logintern0918 小时前
windows如何设置mongodb的副本集
数据库·windows·mongodb
Chandler241 天前
一图掌握 操作系统 核心要点
linux·windows·后端·系统
ajassi20001 天前
开源 C# 快速开发(十七)进程--消息队列MSMQ
windows·开源·c#
Python私教1 天前
5分钟上手 MongoDB:从零安装到第一条数据插入(Windows / macOS / Linux 全平台图解)
windows·mongodb·macos