2016-08-20 73 views
0

我需要保留一些從測試到測試的cookie,我使用Nightwatch和Selenium,我不知道如何讓它們在當前會話中存儲它們。在測試之間保留cookie夜間硒

我試圖創建和設置一個帳戶,但似乎並沒有工作,要麼

"selenium" : { 
"start_process" : false, 
"server_path" : "", 
"log_path" : "", 
"host" : "127.0.0.1", 
"port" : 4444, 
"cli_args" : { 
    "webdriver.chrome.driver" : "", 
    "webdriver.ie.driver" : "", 
    "webdriver.firefox.profile" : "webdriver" 
} 
    }, 

任何幫助apreciated。謝謝

回答

0

由於v0.9.14的,setCookie不會保留測試之間的cookie。看起來客戶端是爲每個測試重新創建的。

我所做的是創建一個custom command,它設置和緩存cookie值。由於自定義命令是單例,因此這對維護測試之間的身份驗證狀態非常有效。實際身份驗證只發生一次,隨後的調用使用setCookie和緩存的會話值。

請記住,setCookie將不會工作,直到客戶端已導航到相關的域。

+0

好奇你是如何緩存cookie的?裏面的夜店全球? – Hans

-1

我們如何在Nightwatch中設置Cookie。我在Supertest嘗試它的作品。 如何在夜間做。

下面是superTest

var args = { 

      data: { 
        email: "xxxx", 
        password: "xxxx" 
       }, 
       headers: { 
        "Content-Type": "application/json" 
       } 
      }; 
      service.post("localhost", args, function(data, response) { 
       global.Cookies = response.headers['set-cookie'].pop().split(';')[0] 
       this.meServiceUrl = superTest.agent("localhost/users").get(''); 
       // Set cookie to get saved user session 
       this.meServiceUrl.cookies = Cookies; 
       this.meServiceUrl.set('Accept', 'application/json') 
        .expect('Content-Type', /json/) 
        .expect(200) 
        .end(function(err, res) { 
         usersApiResponse = res.body 
         usersServiceResponse.push(usersApiResponse) 
        console.log(usersServiceResponse) 
         console.log(usersApiResponse.result.length) 
        }); 
      });