从 Travis 上的 Protractor 在 Sauce Labs 上运行 e2e 测试

2024-03-06

所以我有我的开源项目(https://github.com/ahmednuaman/radian https://github.com/ahmednuaman/radian)并且我有一些可以在本地运行良好的 e2e 测试量角器 https://github.com/angular/protractor.

我已经按照酱汁实验室文档 https://saucelabs.com/tests并设置我的.travis.yml https://github.com/ahmednuaman/radian/blob/feature-23-an/.travis.yml因此。测试运行到 Protractor 尝试连接到 Sauce Labs 上的 selenium 服务器的位置,这是错误的简短快照:

Running "exec:e2e" (exec) task
Using the selenium server at ahmednuaman-radian:06dd4e07-0f52-4fdf-be5e-389f2117bbf5@localhost:4445
>> 
>> timers.js:103
>> if (!process.listeners('uncaughtException').length) throw e;
>> ^
>> TypeError: Cannot read property 'length' of undefined
>>     at HttpClient.send (/home/travis/.nvm/v0.8.26/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:62:16)

这是完整的工作日志:https://travis-ci.org/ahmednuaman/radian/jobs/16250460 https://travis-ci.org/ahmednuaman/radian/jobs/16250460

所以我接下来做的就是尝试在本地模仿这一点。我读了Sauce Labs Connect 文档 https://saucelabs.com/docs/connect最终在我的终端中运行了这个:

java -jar ~/bin/Sauce-Connect.jar USERNAME PASSWORD

一切开始都很好,和 Travis 上的一模一样 https://travis-ci.org/ahmednuaman/radian/jobs/16250460#L7294但当我然后跑我的grunt e2e任务(更新后protractor.conf.coffee https://github.com/ahmednuaman/radian/blob/feature-23-an/test/e2e/protractor.conf.coffee以匹配本地的 Travis 配置)并收到与 Travis 相同的错误,这是一个快照:

Running "exec:e2e" (exec) task
Using the selenium server at ahmednuaman-radian:06dd4e07-0f52-4fdf-be5e-389f2117bbf5@localhost:4445
>> 
>> /Users/ahmed/bin/node/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1542
>>       throw error;
>>             ^
>> TypeError: Cannot read property 'length' of null
>>     at HttpClient.send (/Users/ahmed/bin/node/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:62:16)

我用谷歌搜索了一下,但找不到其他人遇到这个问题。那么,这是我的配置吗?这是量角器/网络驱动程序问题吗?愿意解释一下吗?


好吧,再次重新阅读所有文档后,我发现我的config.seleniumAddress是不正确的,因为它缺少/wd/hub路径在最后;然后我收到一个新错误:它抱怨我的凭据。

在深入研究 Protractor 的源代码之后发现这个很奇怪 https://github.com/angular/protractor/blob/master/lib/runner.js#L151,它基本上消灭了所有sauce*如果我指定一个凭据seleniumAddress,所以我从我的配置中删除了它,再次尝试,它成功了!呜呜!这是 Travis 的输出,只是为了好玩:https://travis-ci.org/ahmednuaman/radian/jobs/16271613 https://travis-ci.org/ahmednuaman/radian/jobs/16271613

因此,通过 Travis 让 Protractor 在 Sauce Labs 上运行的方法是使用以下配置选项:

config.sauceUser = process.env.SAUCE_USERNAME
config.sauceKey = process.env.SAUCE_ACCESS_KEY
config.capabilities =
  'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER
  'build': process.env.TRAVIS_BUILD_NUMBER

And not添加一个seleniumAddress.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 Travis 上的 Protractor 在 Sauce Labs 上运行 e2e 测试 的相关文章

随机推荐