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
相关推荐
2601_9623649714 小时前
Windows Hello VS 传统密码:身份认证安全层级全面对比分析
windows·安全·电脑
Imagine Miracle18 小时前
【WSL】让WSL2后台持久运行不自动关闭的解决方案
linux·windows·wsl
啦啦啦~~~22218 小时前
经典小游X,免费刺激,可离线使用!
windows·游戏·开源软件
月走乂山20 小时前
Windows提示调制解调器报错、同交换机其他电脑正常、远程能连但浏览器打不开——本机DNS配置问题排查
windows·dns·故障排查·网络故障·网络诊断
衔烛之龙11 天前
Windows x64 构建 liboqs-java教程
java·windows·python
阿豪只会阿巴1 天前
两小时快速入门 FastAPI--第二回
windows·python·fastapi
印度神油92 天前
Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
windows·python·ci/cd
2601_963771372 天前
Hardening Enterprise WordPress Sites Against REST API Leaks and Bad Headers
前端·windows·word·php
不要小看我们之间的羁绊啊2 天前
【windows】cc + cc switch + headroom
windows
找死的豆腐2 天前
基于.NET的Windows窗体编程之WinForms图像控件
windows·.net