How to tell Protractor to use hash in baseUrl globally?

拜拜、爱过 提交于 2019-12-11 17:50: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:

  • Expected 'http://localhost:49152/#/login' to be 'http://localhost:49152/login'.

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


回答1:


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


来源:https://stackoverflow.com/questions/53111119/how-to-tell-protractor-to-use-hash-in-baseurl-globally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!