How can I add URL's dynamically to Protractor tests?
Asked Answered
C

4

4

I am trying to use protractor in conjunction with Jenkins. In my jenkins, I need to have URLs dynamically generated.

So while running protractor tests, for example:

describe('angularjs homepage', function() {
  it('should greet the named user', function() {
    // Load the AngularJS homepage.
    browser.get('http://www.angularjs.org');

    element(by.model('yourName')).sendKeys('testUser');

  });
});

In above example I want to pass a variable dynamically in place of "http://www.angularjs.org".

I could not find any variables that can be specified in the reference config as well.

Cherice answered 14/4, 2014 at 14:10 Comment(0)
R
4

If I understand the question correctly, you are looking for the environmental variable to configure the base url. In that case, since Protractor is built on WebDriver you should be able to set

webdriver.base.url="http://someurl"

Hopefully this is what you are looking for.

Readability answered 14/4, 2014 at 14:33 Comment(1)
Yes I think this is the one. I will work on it. Thanks.Cherice
C
8

You can use baseUrl as config parameter inside exports.config and then use browser.get('/path') inside your test spec. So in config you have e.g. baseUrl: 'http://localhost', so browser.get('/path') would call http://localhost/path.

Cochineal answered 27/5, 2014 at 6:42 Comment(0)
R
4

If I understand the question correctly, you are looking for the environmental variable to configure the base url. In that case, since Protractor is built on WebDriver you should be able to set

webdriver.base.url="http://someurl"

Hopefully this is what you are looking for.

Readability answered 14/4, 2014 at 14:33 Comment(1)
Yes I think this is the one. I will work on it. Thanks.Cherice
H
0

It looks like calling browser.baseUrl = "https://test-url.com" does the trick in onPrepare

Hanlon answered 9/12, 2014 at 22:0 Comment(0)
C
0

you must have conf.js or conf.ts file. So, You can set "baseUrl" as part of your conf file under config

// conf.js
exports.config = {
  framework: 'jasmine',
  specs: ['spec.js'],
  baseUrl: 'my-site.com'
}

then call this browser in your test like:

browser.get(browser.baseUrl);

I faced same issue and resolved like this.

Contraposition answered 20/1, 2020 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.