我正在使用弹簧启动应用程序。它有一口气。当应用程序启动时,我会转到
目录 vegan@vegan:~/hb-xx/gateway$ ls
bower.json gateway.iml gulp gulpfile.js
logs mvnw mvnw.cmd node_modules package.json pom.xml README.md src target
并运行此命令以运行e2e tst
vegan@vegan:~/hb-xx/gateway$ gulp protractor
[21:35:55] Using gulpfile ~/hb-xx/gateway/gulpfile.js
[21:35:55] Starting 'protractor'...
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
Started
..
2 specs, 0 failures
Finished in 23.814 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
[21:36:20] Finished 'protractor' after 24 s
它运行良好。
但是我不想每次想要运行测试时都要申请,所以我将量角器下载到本地机器上手动运行。
所以我去了conf
所在的目录:
vegan@vegan:~/hb-xx/gateway/src/test/javascript$ ls
e2e karma.conf.js protractor.conf.js spec testcaner
然后运行测试:
vegan@vegan:~/hb-xx/gateway/src/test/javascript$ protractor protractor.conf.js
[21:36:24] I/direct - Using ChromeDriver directly...
[21:36:24] I/launcher - Running 1 instances of WebDriver
Started
FF
Failures:
1) Login module should fail to login with wrong password
Message:
Failed: WebElementCondition did not resolve to a WebElement: [object Object]
Stack:
TypeError: WebElementCondition did not resolve to a WebElement: [object Object]
at TypeError (native)
at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:722:17
at ManagedPromise.invokeCallback_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1379:14)
at TaskQueue.execute_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14)
at TaskQueue.executeNext_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21)
at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2775:27
at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: Run it("should fail to login with wrong password") in control flow
at Object.<anonymous> (/usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:79:14)
From asynchronous test:
Error
at Suite.<anonymous> (/home/vegan/hb-xx/gateway/src/test/javascript/e2e/account/login/loginControllerSpec.js:13:9)
at Object.<anonymous> (/home/vegan/hb-xx/gateway/src/test/javascript/e2e/account/login/loginControllerSpec.js:8:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
2) Login module should be able to login as a cta
Message:
Failed: WebElementCondition did not resolve to a WebElement: [object Object]
Stack:
TypeError: WebElementCondition did not resolve to a WebElement: [object Object]
at TypeError (native)
at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:722:17
at ManagedPromise.invokeCallback_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1379:14)
at TaskQueue.execute_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14)
at TaskQueue.executeNext_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21)
at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2775:27
at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: Run it("should be able to login as a cta") in control flow
at Object.<anonymous> (/usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:79:14)
From asynchronous test:
Error
at Suite.<anonymous> (/home/vegan/hb-xx/gateway/src/test/javascript/e2e/account/login/loginControllerSpec.js:26:9)
at Object.<anonymous> (/home/vegan/hb-xx/gateway/src/test/javascript/e2e/account/login/loginControllerSpec.js:8:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
2 specs, 2 failures
Finished in 17.017 seconds
[21:36:42] I/launcher - 0 instance(s) of WebDriver still running
[21:36:42] I/launcher - chrome #01 failed 2 test(s)
[21:36:42] I/launcher - overall: 2 failed spec(s)
[21:36:42] E/launcher - Process exited with error code 1
我有2个小班
'use strict';
var LoginPageObject = require('./loginControllerPageObject');
describe(
'Login module', function () {
var loginPageObject = new LoginPageObject();
it(
'should fail to login with wrong password', function () {
loginPageObject.login('wrong','123');
expect(
loginPageObject.loginTextLocator.getText()
).toMatch(loginPageObject.loginText);
}
);
it(
'should be able to login as a admin', function () {
loginPageObject.login('admin','asd-**326SMmasdsa);
}
);
}
);
和其他班级
'use strict';
var CommonPageObject = require('../commonPageObject');
var LoginPageObject = function() {
var commonPageObject = new CommonPageObject();
this.login = element(by.css('[data-menu-item="login"]'));
this.username = element(by.model('vm.model.username'));
this.password = element(by.model('vm.model.password'));
this.loginButton = element(by.css('[aria-label="login.button"]'));
this.loginTextLocator = element(by.css('[class="md-headline ng-scope"]'));
this.loginText = /Giriş/;
this.baseUrl=commonPageObject.baseUrl;
this.login = function(name,password) {
this.get();
browser.driver.wait(protractor.until
.elementIsVisible(element(by.css('header'))));
this.setName(name);
this.setPassword(password);
this.loginButton.click();
};
this.get = function() {
browser.get(commonPageObject.baseUrl+'/#account/login');
};
this.setName = function(name) {
this.username.clear().sendKeys(name);
};
this.setPassword = function(password) {
this.password.clear().sendKeys(password);
};
};
module.exports = LoginPageObject;
和其他班级
'use strict';
var CommonPageObject = function() {
this.baseUrl = "http://xxx:8080";//i am changing this to another website while not using local
};
module.exports = CommonPageObject;
我试过这个
将protractor.until
更改为browser.until或driver.until
this.get();
browser.driver.wait(protractor.until
.elementIsVisible(element(by.css('header'))));
但
给出错误
essage:
Failed: Cannot read property 'elementIsVisible' of undefined
Stack:
TypeError: Cannot read property 'elementIsVisible' of undefined
at null.login (/home/vegan/hb-productupload/gateway/src/test/javascript/e2e/account/login/loginControllerPageObject.js:29:13)
this lien
.elementIsVisible(element(by.css('header'))));
答案 0 :(得分:3)
看起来,如果直接使用protractor
运行测试,则不会提供您的应用,因此测试失败。他们以这种方式失败的原因是因为你正在使用webdriver的browser.driver.wait()
,而是使用量角器的预期条件。替换:
browser.driver.wait(protractor.until
.elementIsVisible(element(by.css('header'))));
使用:
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(element(by.css('header')));
另见相关问题: