使用Angular 5,CLI v1.5,运行e2e测试。我在另一个终端窗口运行服务。当我运行测试时,它打开浏览器,登录,然后开始执行 - 但它总是在大约10秒后给出错误failed to connect, please retry
。
我们有一个假的STS登录页面,它不是Angular,所以我已经禁用,然后重新启用Angular。这一切都有效,它会登录并点击,但10秒后会出错。
app.e2e-spec.ts
:
import { AppPage } from "./page-objects/app.po";
import { OrderPage } from "./page-objects/order.po";
describe("tslint App", () => {
let homePage: AppPage;
let orderPage: OrderPage;
beforeEach(() => {
homePage = new AppPage();
orderPage = new OrderPage();
});
it("should navigate around orders", () => {
homePage.disableAngular();
homePage.navigateToSTS();
homePage.selectUser();
homePage.clickSignIn();
homePage.enableAngular();
expect(homePage.getParagraphText()).toEqual("First LAST");
homePage.clickOrder();
expect(orderPage.selectHeader()).toEqual("Orders");
orderDashboardPage.clickCreateOrder();
[.... etc]
});
});
protractor.conf.js
:
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require("jasmine-spec-reporter");
exports.config = {
allScriptsTimeout: 21000,
specs: ["./js/e2e/**/*.e2e-spec.ts"],
capabilities: {
browserName: "chrome"
},
useAllAngular2AppRoots: true,
directConnect: true,
baseUrl: "http://localhost/",
framework: "jasmine",
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require("ts-node").register({
project: "./js/e2e/tsconfig.e2e.json"
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
debug: true,
nodeDebug: true,
troubleshoot: true,
};
终端输出:
C:\Code\>ng e2e -s false
(node:15364) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[11:28:37] I/update - chromedriver: file exists C:\Code\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver_2.33.zip
[11:28:37] I/update - chromedriver: unzipping chromedriver_2.33.zip
[11:28:37] I/update - chromedriver: chromedriver_2.33.exe up to date
[11:28:37] D/launcher - Running with --troubleshoot
[11:28:37] D/launcher - Protractor version: 5.2.0
[11:28:37] D/launcher - Your base url for tests is http://localhost/
Debugger listening on ws://127.0.0.1:9229/13448c66-b08b-448f-8838-0b1ff17c53c5
For help see https://nodejs.org/en/docs/inspector
[11:28:37] I/launcher - Running 1 instances of WebDriver
(node:18304) [DEP0068] DeprecationWarning: `node debug` is deprecated. Please use `node inspect` instead.
connecting to localhost:5858 ...[11:28:38] I/direct - Using ChromeDriver directly...
DevTools listening on ws://127.0.0.1:12608/devtools/browser/3763eefb-c5ae-4f7d-82bd-c99d98aee99c
.[11:28:39] D/runner - WebDriver session successfully started with capabilities Capabilities {
map_:
Map {
'acceptSslCerts' => true,
'applicationCacheEnabled' => false,
'browserConnectionEnabled' => false,
'browserName' => 'chrome',
'chrome' => { chromedriverVersion: '2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f)',
userDataDir: 'C:\\Users\\CONTWE~1\\AppData\\Local\\Temp\\scoped_dir20368_5804' },
'cssSelectorsEnabled' => true,
'databaseEnabled' => false,
'handlesAlerts' => true,
'hasTouchScreen' => false,
'javascriptEnabled' => true,
'locationContextEnabled' => true,
'mobileEmulationEnabled' => false,
'nativeEvents' => true,
'networkConnectionEnabled' => false,
'pageLoadStrategy' => 'normal',
'platform' => 'Windows NT',
'rotatable' => false,
'setWindowRect' => true,
'takesHeapSnapshot' => true,
'takesScreenshot' => true,
'unexpectedAlertBehaviour' => '',
'version' => '62.0.3202.94',
'webStorageEnabled' => true } }
[11:28:39] D/runner - Running with spec files C:\Code\js\e2e\app.e2e-spec.ts
........ failed to connect, please retry
[11:28:52] E/launcher - Process exited with error code 1
答案 0 :(得分:0)
尝试运行webdriver-manager update
来安装本地chromedriver,然后您不需要在量角器配置中设置 chromeDriver 设置
exports.config = {
directConnect: true,
chromeDriver: chromeDriverPath, <--
specs: [
'features/*.feature'
],
capabilities: {
browserName: 'chrome',
platform: 'ANY',
chromeOptions: {
args: ['--test-type']
}
}
}