Skip to content

Commit

Permalink
WIP smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
serbanghita committed Dec 7, 2023
1 parent 7ea6835 commit 880f613
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
6 changes: 4 additions & 2 deletions test/e2e/fixtures/form-single-choice-fields.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form action="/submit" method="post" data-testid="testForm">
<form action="/submit" method="post" data-testid="testForm" id="testForm">
<label for="text">Text:</label>
<input type="text" id="text" name="text"><br><br>

Expand Down Expand Up @@ -55,4 +55,6 @@

<label for="reset">Reset:</label>
<input type="reset" id="reset" value="Reset"><br><br>
</form>
</form>

<script src="./js/formToObject.js"></script>
61 changes: 48 additions & 13 deletions test/e2e/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,69 @@ import { expect, browser } from '@wdio/globals'
import path from "path";

describe('smoke', () => {
it('multiple choice fields form', async () => {
it.skip('all multiple choice fields form', async () => {
await browser.url(`form-multiple-choice-fields.html`);

// await $('#testForm').waitForDisplayed();
// const $formEl = await $('#testForm');

await $('#multiSelect').selectByAttribute('value', 'option2');
await $('#multiSelect').selectByAttribute('value', 'option3');

await $('#checkboxGroup-2').click();
await $('#checkboxGroup-3').click();

// https://webdriver.io/blog/2019/06/25/file-upload/
const $fileUpload = await $('#fileUpload');
const filePath1 = path.join(__dirname, 'fixtures/files/a.txt');
// const filePath2 = path.join(__dirname, 'fixtures/files/b.txt');
const result = await browser.executeScript('return formToObject("testForm")', []);
await expect(result).toEqual({"checkboxGroup": ["option2", "option3"], "multiSelect": ["option2", "option3"]});

const remoteFilePath = await browser.uploadFile(filePath1);
$fileUpload.setValue(remoteFilePath);
});

it('all single choice fields', async () => {
await browser.url(`form-single-choice-fields.html`);

await $('#text').setValue('text field value');
await $('#password').setValue('password field value');
await $('#email').setValue('[email protected]');
await $('#number').setValue(123456);
await $('#date').setValue('12/09/2023');
await $('#time').setValue('00:16');
await $('#range').setValue(30);
await $('#color').setValue('#703333');
await $('#checkbox').click();
await $('#radio2').click();
const filePath = path.join(__dirname, 'fixtures/files/a.txt');
const remoteFilePath = await browser.uploadFile(filePath);
await $('#file').setValue(remoteFilePath);
await $('#textarea').setValue('textarea value');
await $('#select').selectByAttribute('value', 'option2');
await browser.executeScript('return document.getElementById("hidden").value = "hidden value";', []);

const result = await browser.executeScript('return formToObject("testForm")', []);
// await browser.debug(9999);
await expect(result).toEqual({
'text': 'text field value',
'password': 'password field value',
'email': '[email protected]',
'number': "123456",
'date': '2023-12-09',
'time': '00:16',
'range': 30,
'color': '#703333',
'checkbox': true,
'radio': 'option2',
'file': 'fixtures/files/a.txt',
'textarea': 'textarea value',
'select': 'option2',
'hidden': 'hidden value'
});

});

await expect(result).toEqual({"checkboxGroup": ["option2", "option3"], "multiSelect": ["option2", "option3"]});
it.skip('file field', async () => {

})
// https://webdriver.io/blog/2019/06/25/file-upload/
const $fileUpload = await $('#fileUpload');
const filePath1 = path.join(__dirname, 'fixtures/files/a.txt');
// const filePath2 = path.join(__dirname, 'fixtures/files/b.txt');

const remoteFilePath = await browser.uploadFile(filePath1);
await $fileUpload.setValue(remoteFilePath);
});
})

0 comments on commit 880f613

Please sign in to comment.