gpt4 book ai didi

javascript - 如何在 docker-compose 中运行 Protractor 测试

转载 作者:行者123 更新时间:2023-12-02 18:39:01 25 4
gpt4 key购买 nike

我在使用 docker image 使用 Protractor 框架开始测试时遇到问题。当我在本地 selenium 服务器中开始测试时,测试成功。
但是当我使用 docker 镜像时,我得到了错误 E/Protractor - 在页面 http://localhost:4200/ 上找不到 Angular : 重试寻找 Angular 超出 .

我的 config.js

exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://hub:4444/wd/hub',
specs: ['e2e/myTest.js'],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
args: ['--no-sandbox']
}
},
chromeOnly: true
};

myTest.js
describe('example test', function() {
var homePage = require('./pages/homePage.js');
var homePage = new homePage();

it('my test...', function() {

browser.get('http://localhost:4200/');
....

包.json 文件
{
"name": "client",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "npm install && ng serve -H 0.0.0.0",
"build": "ng build",
"pretest": "webdriver-manager update",
"test": "protractor config.js",
"lint": "ng lint"
},

docker-compose.yml 的片段
  angular:...
mypayara:...
chrome:
image: selenium/node-chrome:3.9.1-actinium
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
hub:
image: selenium/hub:3.9.1-actinium
ports:
- "4444:4444"
depends_on:
- angular

当我使用命令开始测试时

docker-compose exec angular sh -c "npm test"



我得到了那个错误
[18:51:48] E/protractor - Could not find Angular on page http://localhost:4200/ : retries looking for angular exceeded
F[18:51:59] E/protractor - Could not find Angular on page http://localhost:4200/ : retries looking for angular exceeded
F

Failures:
1) Register account test should create a account
Message:
Failed: Angular could not be found on the page http://localhost:4200/.If this is not an Angular application, you may need to turn off waiting for Angular.
Please see
https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load
Stack:
Error: Angular could not be found on the page http://localhost:4200/.If this is not an Angular application, you may need to turn off waiting for Angular.
Please see
https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load
at executeAsyncScript_.then (/usr/src/app/node_modules/protractor/built/browser.js:720:27)
at ManagedPromise.invokeCallback_ (/usr/src/app/node_modules/selenium-webdriver/lib/promise.js:1376:14)
at TaskQueue.execute_ (/usr/src/app/node_modules/selenium-webdriver/lib/promise.js:3084:14)
at TaskQueue.executeNext_ (/usr/src/app/node_modules/selenium-webdriver/lib/promise.js:3067:27)
at asyncRun (/usr/src/app/node_modules/selenium-webdriver/lib/promise.js:2927:27)
at /usr/src/app/node_modules/selenium-webdriver/lib/promise.js:668:7
at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: Run it("should create a account") in control flow
at UserContext.<anonymous> (/usr/src/app/node_modules/jasminewd2/index.js:94:19)
From asynchronous test:
Error
at Suite.<anonymous> (/usr/src/app/e2e/registertest.js:7:3)
at Object.<anonymous> (/usr/src/app/e2e/registertest.js:1:63)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)

我在连接我的 docker 应用程序时遇到问题。我正在尝试这个测试,结果是成功的。
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('https://angularjs.org');

element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();

var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');

// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
});

你知道我能解决这个问题吗?

最佳答案

只是为了检查原因是否是 Angular,将此行添加到“it” block 中的代码中。

await browser.waitForAngularEnabled(false);

并观察正在发生的事情

关于javascript - 如何在 docker-compose 中运行 Protractor 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48966664/

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