使用量角器在测试E2E中上传文件

问题描述 投票:0回答:1

在测试中,我有一个用于浏览光盘并选择文件的按钮。

我想使用function(el: WebElement),但出现错误:

import { ElementFinder, browser, by, element } from 'protractor';

SyntaxError:无法在模块外部使用import语句

我在[[fic_test.js中的代码:]]it("Upload file",function(){ let filePath = "../../../PJ/a.jpg"; let fpath = path.resolve(__dirname,filePath); browser.get("..."); browser.sleep(5000); browser.findElement(by.xpath('//button[contains(.," Télécharger un autre document ")]')).then(function(el: WebElement){ browser.executeScript("arguments[0].scrollIntoView(true);",el); el.sendKeys(fpath); });

我的项目中的文件:

    conf / conf.js
  • tests / fic_test.js
  • 在测试中,我有一个用于浏览光盘并选择文件的按钮。我想使用function(el:WebElement),但出现错误:从'...
  • angular protractor node-modules
    1个回答
    0
    投票
    const EC = ExpectedConditions; it('Upload file', () => { const filePath = '../../../PJ/a.jpg'; const absolutePath = require('path').resolve(__dirname, filePath); browser.get("..."); // maybe add here a little wait browser.wait(EC.presenceOf($('cssSelector-of-ur-input-el')), 5000, 'ERROR: Input el. not found'); $('cssSelector-of-ur-input-el').sendKeys(absolutePath); });

    我发现没有真正的需要将页面滚动到所使用的元素,因为量角器唯一需要的是它的存在,希望它可以帮助:)

    © www.soinside.com 2019 - 2024. All rights reserved.