How to use browser.getCurrentUrl() in a protractor test?

前端 未结 2 1429
温柔的废话
温柔的废话 2020-12-18 06:22

I have been struggling with these lines of Protractor code today:

element(by.linkText(\"People\")).click();
browser.waitForAngular();        
var url = brows         


        
相关标签:
2条回答
  • 2020-12-18 06:39

    Instead of waitForAngular() call, wait for the URL to change:

    browser.wait(function() {
      return browser.getCurrentUrl().then(function(url) {
        return /index/.test(url);
      });
    }, 10000, "URL hasn't changed"); 
    

    Originally suggested by @juliemr at UnknownError: javascript error: document unloaded while waiting for result.

    0 讨论(0)
  • 2020-12-18 06:41

    This piece of code works correctly

    var handlePromise = browser.driver.getAllWindowHandles();
    handlePromise.then(function (handles) {
        // parentHandle = handles[0];
        var popUpHandle = handles[1];
    
        // Change to new handle
        browser.driver.switchTo().window(popUpHandle).then(function() {
            return browser.getCurrentUrl().then(function(url) {
                console.log("URL= "+ url);
            });
        })
    });
    
    0 讨论(0)
提交回复
热议问题