2016-03-18 21 views
1

我有一個函數,它從DB讀取電子郵件並將其存儲在桌面上。在量角器中獲取currentUrl後,如何更改Url的第一部分?

該電子郵件是用於密碼重置電子郵件。即使在測試中,url也始終指向Prod。我需要將字符串的第一部分替換爲-test。我怎樣才能做到這一點?

 browser.getCurrentUrl().then(function(CurrentUrl) { 
    var modifyUrl = CurrentUrl;// Getting current url 

    console.log(modifyUrl);//This one has the current Url 

//The modifyUrl looks like this https://login.domain.com/reset/####.. 
//I want to replace just login to login-test 
// I tried the following but I am getting Window is undefined message. 

var URL = window(modifyUrl).location.toString(); 
window.location = URL.replace(/login/, 'login-test') 

}); 

欣賞幫助

回答

1

你不必直接訪問window對象在您的測試(你可以儘管通過browser.executeScript()訪問它如果需要的話)。

而不是修改window.location的,使用browser.get()

var url = CurrentUrl.replace(/login\.domain\.com/, 'login-test.domain.com'); 
browser.get(url); 

我也改善您的更換邏輯了一下,以避免login在URL中的其他配件的更換。

+0

謝謝a bunchhhhhhhhhh ...工作。 :) – user2744620