How to tell Protractor to use hash in baseUrl glob

2019-08-17 08:04发布

Currently, HashLocationStrategy is enabled in my Angular App, and when I run

  expect(browser.getCurrentUrl()).toBe(browser.baseUrl + '/login');

in my e2e spec, I receive following error:

Is there a way to tell Protractor to use hash suffix in baseUrl globally?

1条回答
beautiful°
2楼-- · 2019-08-17 08:45

You can define baseUrl in your config file Or pass parameter from command line or Jenkins so that it would be available to all specs.

exports.config = {
    seleniumServerJar: '../../node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.11.0.jar',
    specs: ['../spec/*.js'],
    framework:'jasmine2',
    baseUrl: "http://localhost:49152/#/"
}

And can check expectation,

expect(browser.getCurrentUrl()).toBe(browser.baseUrl + 'login');
expect(browser.getCurrentUrl()).toContain(browser.baseUrl + 'login');

Or if you pass parameter from command line,

protractor --baseUrl='http://localhost:49152/#/' protractor.conf.js
查看更多
登录 后发表回答