如何Git bash CLI console在運行賽普拉斯測驗時列印賽普拉斯基礎網址?有人可以建議嗎?
uj5u.com熱心網友回復:
無頭運行時,瀏覽器日志不會顯示在終端中,但來自賽普拉斯節點行程(又名cy.task())的日志會顯示。
我假設在測驗期間 baseUrl 正在發生變化,這里有一個例子,它使用任務記錄當前值。
配置的值為http://localhost:3000,測驗將其更改為http://localhost:3001。
cypress.config.js
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
console.log('Printing baseUrl - during setup', config.baseUrl)
on('task', {
logBaseUrl(baseUrl) {
console.log('Printing baseUrl - from task', baseUrl)
return null
}
})
},
baseUrl: 'http://localhost:3000'
},
})
測驗
it('logs baseUrl to the terminal in run mode', () => {
console.log('Printing baseUrl - directly from test', Cypress.config('baseUrl')) // no show
Cypress.config('baseUrl', 'http://localhost:3001')
cy.task('logBaseUrl', Cypress.config('baseUrl'))
})
終端
Printing baseUrl - during setup http://localhost:3000
====================================================================================================
Running: log-baseurl.cy.js (1 of 1)
Printing baseUrl - from task http://localhost:3001
√ logs baseUrl to the terminal in run mode (73ms)
1 passing (115ms)
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: 0 seconds │
│ Spec Ran: log-baseurl.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ √ log-baseurl.cy.js 108ms 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
√ All specs passed! 108ms 1 1 - - -
Done in 18.49s.
uj5u.com熱心網友回復:
您可以使用nodejs 命令console.log(Cypress.config().baseUrl)。
不過,這不需要 Git Bash,只需要在您的 Windows 上安裝 nodejs。
或者您可以添加您的測驗cy.config().baseUrl。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/532333.html
