Skip to content

Commit

Permalink
Merge pull request #4097 from snysmymric/anna-commit-007-discuss
Browse files Browse the repository at this point in the history
[Issue #WV-615] Reimplemented test 007 Discuss Page
  • Loading branch information
DaleMcGrew authored Oct 10, 2024
2 parents b08f8f1 + 595f57f commit 09b981b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
22 changes: 21 additions & 1 deletion tests/browserstack_automation/page_objects/discuss.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ class DiscussPage extends Page {
async toggleEmailVerificationButton () {
await this.voterEmailAddressVerificationButton.findAndClick();
}
}

async tabToSelectElement(driver, targetElementId) {
// Max number of iterations to find target element.
// Prevents waiting for a timeout when the element is missing or unreachable.
const maxCount = 100;
let count = 0;

let activeElement;
let activeElementId;

do {
await driver.keys(['Tab']);
activeElement = await driver.getActiveElement();
activeElementId = await (await $(activeElement)).getProperty('id');
if (targetElementId === activeElementId) {
return $(activeElement);
}
++count;
} while (activeElementId !== targetElementId && count <= maxCount);
return null;
}
}
export default new DiscussPage();
28 changes: 14 additions & 14 deletions tests/browserstack_automation/specs/DiscussPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DiscussPage from '../page_objects/discuss.page';
const { describe, it } = require('mocha');

const waitTime = 5000;
const email = '[email protected]';


describe('Discuss Page', () => {
Expand Down Expand Up @@ -35,7 +36,7 @@ describe('Discuss Page', () => {
await expect(DiscussPage.voterEmailAddressVerificationButton).not.toBeClickable();
const element = await DiscussPage.enterVoterEmailAddressTextBox; // Locate the text box element using a selector
await driver.pause(waitTime);
element.setValue('[email protected]');
element.setValue(email);
await driver.pause(waitTime);
await driver.waitUntil(async () => ((DiscussPage.toggleEmailVerificationButton)));
});
Expand Down Expand Up @@ -73,23 +74,22 @@ describe('Discuss Page', () => {
});

// Discuss_007
it('verifyTabKeySelectenterVoterEmailAddressTextBox', async () => {
it('verifyTabKeySelectEnterVoterEmailAddressTextBox', async () => {
await DiscussPage.load();
await driver.switchWindow('https://quality.wevote.us/news');

const element = await DiscussPage.enterVoterEmailAddressTextBox; // Locate the text box element using a selector
element.setValue('[email protected]');
// Press the tab key 11 times
for (let i = 0; i < 12; i++) {
driver.keys(['Tab']);
const element = await DiscussPage.enterVoterEmailAddressTextBox;
const elementId = await element.getAttribute('id');

const voterEmailAddressTextBox = await DiscussPage.tabToSelectElement(driver, elementId);
if (voterEmailAddressTextBox) {
await voterEmailAddressTextBox.setValue(email);
} else {
throw new Error('Element with ID ' + elementId + ' not found or not reachable while selectig with Tab.');
}
await driver.pause(waitTime);
// Check if the active element is the email text box after pressing the tab key 11 times
const activeElement = await driver.getActiveElement();
const activeElementWdio = await (await $(activeElement)).getProperty('id');
await driver.pause(waitTime);
console.log(activeElementWdio);
await expect(activeElement).toBe(element);

await expect(DiscussPage.voterEmailAddressVerificationButton).toBeClickable();
await expect(await element.getAttribute('value')).toBe(email);
});

// Test Case Doesn't work
Expand Down

0 comments on commit 09b981b

Please sign in to comment.