Skip to content

Instantly share code, notes, and snippets.

@eladrkatz
Created March 30, 2020 14:51
Show Gist options
  • Save eladrkatz/2dd747d68f7fc704d70d0d66712ceadd to your computer and use it in GitHub Desktop.
Save eladrkatz/2dd747d68f7fc704d70d0d66712ceadd to your computer and use it in GitHub Desktop.
const webdriverio = require('webdriverio');
const path = require('path');
(async () => {
let browser;
const run = async () => {
browser = await webdriverio.remote({
hostname: 'browsers.aerokube.com',
protocol: 'https',
port: 4444,
path: '/wd/hub',
connectionRetryTimeout: 300000,
user: 'user',
key: 'password',
capabilities: {
browserName: 'MicrosoftEdge',
version: '18',
platform: 'WINDOWS'
}
});
await browser.url('https://the-internet.herokuapp.com/')
const uploadLink = await browser.$("a[href='/upload']");
await uploadLink.click();
const filePath = path.join(__dirname, '/some-file.txt');
const remoteFilePath = await browser.uploadFile(filePath);
const fileInput = await browser.$('#file-upload');
await fileInput.setValue(remoteFilePath);
const fileSubmitBtn = await browser.$('#file-submit');
await fileSubmitBtn.click();
await browser.waitUntil(async () => {
const uploadFilesEl = await browser.$('#uploaded-files');
const uploadFilesText = await uploadFilesEl.getText();
return uploadFilesText.includes('some-file.txt');
});
};
try {
await run();
} catch (err) {
console.error(err);
} finally {
await browser.deleteSession();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment