我正在嘗試使用 cypress 自動上傳檔案,并按照下面的博客安裝依賴項并從我的測驗中呼叫該函式。
import emailSignup from './emailsignup'
import teamSelector from './teamSelector'
import fileupload from './fileupload'
{/* <reference types = "cypress" /> */}
const {commands} = require('../support/commands')
const { Input } = require("@angular/core")
const { wrap } = require("module")
const { isExportSpecifier } = require("typescript")
describe('our first suite', () => {
const signup = new emailSignup()
const signindepartment = new teamSelector()
const uploadfile = new fileupload()
it('first test', () => {
cy.visit('/')
signup.signupforfreelink().click()
cy.get('.flex').should('contain',"Create your free account")
cy.get('[for="emailSignup"]').should('contain',"Work email")
signup.email()
signup.continuebtn()
signup.firstandlastname()
signup.password()
signup.signInButton()
signup.alertsignup()
signup.closealert()
signindepartment.loginselectors('eng')
signup.continuebtn()
signindepartment.customersurvey(2)
signup.continuebtn()
uploadfile.clickexcel()
signup.alertsignup()// switching to the window to interact, reusing previously created fn.
uploadfile.uploadexcel()
})
})
收到錯誤訊息“嘗試包裝已包裝的警報”。我看到使用了 restore 命令,但不確定如何使用我擁有的代碼。
uj5u.com熱心網友回復:
您應該能夠消除cy.wrap().
uploadexcel() {
cy.get('#excel')
.should('be.visible')
.click({force:true})
const csvfile = 'TestData_csv.xlsx';
return cy.get('#fsp-fileUpload') // return last command
.attachFile(csvfile)
.trigger('input')
// .trigger('change') // or this trigger
}
嚴格來說,這return不是必需的,但如果你想像這樣.then()在測驗中添加一個可能會很有用
uploadfile.uploadexcel().then(() => {
// do something after upload completes
})
所以只需回傳最后一個命令即可消除嵌套uploadexcel()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/505365.html
標籤:javascript 上传文件 柏
上一篇:根據輸入的最新資料對兩列進行排序
下一篇:有意思的水平橫向溢位滾動
