gpt4 book ai didi

node.js - 在 Mac OS : "Connection refused! Is selenium server started?" 上使用 Nightwatchjs 在 Chrome 中启动测试

转载 作者:搜寻专家 更新时间:2023-10-31 23:21:33 26 4
gpt4 key购买 nike

我可以使用以下命令在 Firefox 上运行我的测试:

 nightwatch -t tests/test4.js   

我的 nightwatchjs.json 配置文件:

{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"globals_path" : "",

"selenium" : {
"start_process" : true,
"server_path" : "selenium-server-standalone-2.44.0.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "drivers/chromedriver"
}
},

"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},

"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}

但是我无法使用 Chrome 运行测试。这是命令:

nightwatch -t tests/test4.js -e chrome --verbose

输出:

INFO Request: POST /wd/hub/session 
- data: {"desiredCapabilities":{"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY","name":"Test4"}}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":127}
ERROR Response 500 POST /wd/hub/session{ sessionId: null,
status: 13,
state: 'unhandled error',
value:
{ message: null,
localizedMessage: null,
cause: null,
class: 'java.util.concurrent.TimeoutException',
hCode: 1023736867,
screen: null },
class: 'org.openqa.selenium.remote.Response',
hCode: 31447144 }

由于某些原因,相同的主要配置选项适用于 Firefox,但不适用于 Chrome。有人遇到同样的问题吗?

谢谢,保罗

最佳答案

保罗!)尝试在 chrome“desiredCapabilities” block 中使用 selenium CLI 参数。并指定 chromedriver 二进制文件的路径。或者你可以在 Selenium block 中添加它

"cli_args" : {
"webdriver.chrome.driver" : "<path to chromedriver>"
}

http://nightwatchjs.org/guide#settings-file了解更多信息。

但我更喜欢使用类似 bash 脚本的方式运行 selenium 服务器

#!/bin/bash
all="false"
chrome="false"
firefox="false"
phantom="false"
for var in "$@"
do
if [ "$var" == "firefox" ];
then
firefox="true"
fi
if [ "$var" == "chrome" ];
then
chrome="true"
fi
if [ "$var" == "phantomjs" ];
then
phantom="true"
fi
if [ "$var" == "all" ];
then
all="true"
firefox="true"
chrome="true"
phantom="true"
fi
done

if [ "$firefox" == "true" ] && [ "$phantom" == "true" ] && [ "$chrome" == "true" ];
then
all="true"
fi

if [ "$#" -eq 0 ];
then
firefox="true"
fi

echo Selenium will started for chrome: "$chrome"
echo Selenium will started for firefox: "$firefox"
echo Selenium will started for phantomjs: "$phantom"
echo Selenium will started for all browsers: "$all"

if [ "$chrome" == "true" ];
then
nohup java -jar lib/selenium-server-standalone-2.44.0.jar -Dwebdriver.chrome.driver="lib/chromedriver"&
echo $! > sel_pid_head
echo "Selenium server for Chrome and FireFox started"
chrome="false"
firefox="false"
fi

if [ "$firefox" == "true" ];
then
nohup java -jar lib/selenium-server-standalone-2.44.0.jar&
echo $! > sel_pid_head
echo "Selenium server for FireFox started"
firefox="false"
fi

if [ "$all" == "true" ];
then
nohup java -jar lib/selenium-server-standalone-2.44.0.jar -role hub -port 4455&
echo $! > sel_pid_headless
echo "Selenium server for PhantomJS started"
echo "Waiting 3 sec to register ghost driver into Selenium hub"
sleep 3
nohup phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4455&
echo "PhantomJS registred in Selenium Server"
echo $! > ghost_pid
phantom="false"
all="false"
fi

if [ "$phantom" == "true" ]
then
nohup java -jar lib/selenium-server-standalone-2.44.0.jar -role hub -port 4455&
echo $! > sel_pid_headless
echo "Selenium server for PhantomJS started"
echo "Waiting 3 sec to register ghost driver into Selenium hub"
sleep 3
nohup phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4455&
echo "PhantomJS registred in Selenium Server"
echo $! > ghost_pid
phantom="false"
fi

关于node.js - 在 Mac OS : "Connection refused! Is selenium server started?" 上使用 Nightwatchjs 在 Chrome 中启动测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27601103/

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