Remote File Upload Protractor test

前端 未结 3 511
-上瘾入骨i
-上瘾入骨i 2020-12-10 06:54

I am writing tests in protractor which a JS based framework and selenium test stack for running tests. I am facing an issue where I have to test file upload.

Problem

3条回答
  •  北海茫月
    2020-12-10 07:33

    Thanks to @alecxe for his answer!

    I just had this situation, trying to upload some files to BrowserStack. In my case I'm using Cucumber - Protractor - NodeJs - BrowserStack. This code is already tested, working in local env and BorwserStack.

    let path = require('path');
    let remote = require('selenium-webdriver/remote');
    
    this.When(/^I upload a file$/, () => {
        browser.setFileDetector(new remote.FileDetector());
    
        var fileToUpload = '../image_with_title.jpg';
        var absolutePath = path.join(__dirname, fileToUpload);
    
        page.fileupload.sendKeys(absolutePath);
    });
    

    The magic line is:

    let remote = require('selenium-webdriver/remote');
    

提交回复
热议问题