安裝nodejs起因,本地在運(yùn)行appium自動(dòng)化用例時(shí),報(bào)如下錯(cuò)誤:
Running com.vimalselvam.stf.AndroidTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@4361bd48
四月 26, 2021 2:30:07 下午 com.vimalselvam.DeviceApi connectDevice
嚴(yán)重: Device is in use
Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 1.854 sec <<< FAILURE!
setup(com.vimalselvam.stf.AndroidTest) Time elapsed: 1.72 sec <<< FAILURE!
io.appium.java_client.service.local.InvalidNodeJSInstance: Node.js is not installed!
at io.appium.java_client.service.local.AppiumServiceBuilder.findDefaultExecutable(AppiumServiceBuilder.java:20
1)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(AppiumDriverLocalService.java:74)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService(AppiumDriverLocalService.j
ava:70)
at com.vimalselvam.stf.AndroidTest.createAppiumService(AndroidTest.java:35)
at com.vimalselvam.stf.AndroidTest.setup(AndroidTest.java:56)
Caused by: java.lang.NullPointerException: Unable to find executable for: node.exe
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:251)
at org.openqa.selenium.os.UnixProcess.(UnixProcess.java:62)
at org.openqa.selenium.os.CommandLine.(CommandLine.java:38)
at io.appium.java_client.service.local.AppiumServiceBuilder.findDefaultExecutable(AppiumServiceBuilder.java:19
5)
... 38 more
Results :
Failed tests: setup(com.vimalselvam.stf.AndroidTest): Node.js is not installed!
Tests run: 4, Failures: 1, Errors: 0, Skipped: 3
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.593 s
[INFO] Finished at: 2021-04-26T14:30:08+08:00
錯(cuò)誤分析:
從部分關(guān)鍵錯(cuò)誤,很容易看出nodejs沒(méi)有安裝,所以在啟動(dòng)appium server時(shí)報(bào)該錯(cuò)誤。
官網(wǎng)下載對(duì)應(yīng)系統(tǒng)版本即可:http://nodejs.org/download/
下載msi格式的安裝包,直接下一步下一步安裝即可,注意更改安裝路徑(默認(rèn)C盤(pán));
此種方式安裝好以后,會(huì)默認(rèn)把環(huán)境變量配好,可以在cmd命令窗口直接使用。
注意:此處你安裝的版本應(yīng)該是與后面要下載的appium的版本是有關(guān)聯(lián)的,有些版本它不能相互兼容,導(dǎo)致下載不下來(lái)(本例中卸載重裝了3次,從15.0.0->13.13.0->12.9.0)
所以,你可以大致看一下你要用的appium版本它的發(fā)布時(shí)間,然后根據(jù)這個(gè)時(shí)間去找對(duì)應(yīng)的nodejs當(dāng)時(shí)大致的版本,然后下載下來(lái),這樣成功率高一些。
C:\Users\Administrator>node -v
v12.9.0
C:\Users\Administrator>npm -v
6.10.2
#設(shè)置倉(cāng)庫(kù)為 taobao的,這樣安裝軟件的時(shí)候快一些
C:\Users\Administrator>npm config set registry https://registry.npm.taobao.org
如下圖,沒(méi)有安裝成功
解決上述未安裝成功問(wèn)題:
重新卸載了nodejs,中間試過(guò)很多版本,最終能下載成功的版本:v12.9.0
接著參考網(wǎng)上說(shuō)設(shè)置 node_global、node_cache目錄
C:\Users\Administrator>npm config set prefix="D:\\tools\\nodejs\\node_global"
C:\Users\Administrator>npm config set prefix="D:\\tools\\nodejs\\node_cache"
再次下載appium
npm install appium@1.18.0 -g
聯(lián)系客服