【问题标题】:Protractor expect direct to a page with specific url量角器期望直接到具有特定 url 的页面
【发布时间】:2017-12-15 14:08:24
【问题描述】:

我的页面上有一个按钮,我想使用 Protractor 编写一个 e2e 测试。我想要实现的是,当点击按钮时,页面变为http://localhost:8100/#/booking。我该如何实现呢?

describe('booking function', function() {
  it('should go to booking page', function() {
    broswer.get(localHostCruises);
    element(by.css('.button.button-stable.button-block')).click();
    //sudo code
    expect(page change to "http://localhost:8100/#/book" );
  })
})

【问题讨论】:

    标签: jasmine protractor


    【解决方案1】:

    你需要使用browser.getCurrentUrl() 方法,所以是这样的:

    element(by.css('.button.button-stable.button-block')).click().then(function () {
        expect(browser.getCurrentUrl()).toEqual("http://localhost:8100/#/book");
    })
    

    【讨论】:

      【解决方案2】:

      您可以使用以下代码实现此目的。

         let targetLocation = 'your/target/location';
      
          browser.get('localHostCruises'); // Login page.
          element(by.css('.button.button-stable.button-block')).click(); // click on button.
          browser.setLocation(targetLocation);
      
          // If Login takes some time, so wait until it's done.
          browser.wait(() => {
              return browser.getCurrentUrl().then((url) => {
                  let isMatch = url.match(targetLocation);
      
                  if (isMatch) {
                      page = new Page; // I assume you writing test cases in page object.
                  } else {
                      browser.setLocation(targetLocation);
                  }
      
                  return isMatch;
              });
          }, 2000, 'Should throw an error message.');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多