English 中文(简体)
Cypress - File Upload
  • 时间:2024-03-24 09:12:05

Cypress - File Upload

Previous Page Next Page  

To perform file upload task in Cypress, we have to first install a plugin with the command mentioned below −


   npm install –dev cypress-file-upload

以下屏幕将登在你的电脑上:

Upload Task in Cypress

一旦安装完毕,我们就必须在指挥部档案中增加进口气压单上载荷。 这一档案存放在我们“Cypress”项目内。

此外,我们将补充我们想要在固定装置夹中上载的文件(Picture.png文档)。 将展示以下屏幕:

Picture.png file

为了上载档案,我们必须使用Cypress指挥系统,并附上File,并将文档作为参数上载。

Implementation

用于在Cypress上载一个档案的指挥系统如下:


describe( Tutorialspoint Test , function () {
   // test case
   it( Test Case6 , function (){
      //file to be uploaded path in project folder
      const p =  Picture.png 
      // launch URL
      cy.visit("https://the-internet.herokuapp.com/upload")
      //upload file with attachFile
      cy.get( #file-upload ).attachFile(p)
      //cpck on upload
      cy.get( #file-submit ).cpck()
      //verify uploaded file
      cy.get( #uploaded-files ).contains( Picture )
   });
});

产出如下:

Uploading a File in Cypress

执行记录显示档案照片。 png got上载,文档名称反映在网页上。

Advertisements