我尝试上传文件,该文件可与常规Chrome一起使用,但不适用于Chrome无头模式。
我使用量角器5.4.1测试Angular 7.0.2
protractor.base.conf.js:
chrome_HL: {
browserName: 'chrome',
chromeOptions: {
args: [
'--disable-browser-side-navigation',
'--headless',
'--no-sandbox',
'--disable-extensions',
'--disable-dev-shm-usage',
'--window-size=1900,1400'
],
}
}
spec.ts:
describe('Test', () => {
const EC = protractor.ExpectedConditions;
it('Upload files', async (done) => {
let fileToUpload = '../../files-to-upload/image1.jpeg',
absolutePath = path.resolve(__dirname, fileToUpload);
element(by.css('input[type="file"]')).sendKeys(absolutePath);
uploadedImage = element.all(by.css('.image'))
browser.wait(EC.presenceOf(uploadedImage.get(0)), 5000, 'Image is not present on the page');
done();
});
});