Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
fix: update-api-to-match-wdio (#243)
Browse files Browse the repository at this point in the history
* fix: update-api-to-match-wdio
BREAKING CHANGE: update BrowserUtils API to match the wdio api
  • Loading branch information
FelixZilber authored Sep 22, 2021
1 parent 5568964 commit e594ee7
Show file tree
Hide file tree
Showing 42 changed files with 344 additions and 498 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ describeCommon('Test Example', () => {

```json
{
"include": [
"specs/**/*.ts"
]
"include": ["specs/**/*.ts"]
}
```

Expand Down
495 changes: 195 additions & 300 deletions src/commons/BrowserUtils.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/test/TestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function describeCommon(name: string, body: () => any): void {
* Navigate to sampleApp and wait for it to load
*/
beforeEach(() => {
BrowserUtils.navigateToUrl(sampleAppUrl);
BrowserUtils.url(sampleAppUrl);
BrowserUtils.waitForDisplayed("//*[@id='top']");
});

Expand Down
3 changes: 2 additions & 1 deletion src/test/sampleApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ <h1 id="header">Tests Sandbox</h1>
<script>
function disappearBtn() {
window.setTimeout(() => {
document.getElementById('disappearing-btn').style.display = 'none';
const buttonToRemove = document.getElementById("disappearing-btn");
buttonToRemove.remove();
}, 1000);
}
</script>
Expand Down
7 changes: 3 additions & 4 deletions src/test/specs/AddValueSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ describeCommon('addValue', () => {
.contains('still not enabled');
});
it('add value to not existing input', () => {
expect(() => BrowserUtils.addValue(`//input[@id='${TestUtils.randomString(5)}']`, TestUtils.randomString(5)))
.to.throw(Error)
.with.property('message')
.contains('Element not exist');
expect(() =>
BrowserUtils.addValue(`//input[@id='${TestUtils.randomString(5)}']`, TestUtils.randomString(5))
).to.throw(Error);
});
});
4 changes: 2 additions & 2 deletions src/test/specs/BackBrowserSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { describeCommon, sampleAppUrl } from '../TestHelper';

const navigationButton: string = "//button[@data-test='navigate-to-cloudinary']";

describeCommon('BackBrowserSpec', () => {
describeCommon('BackSpec', () => {
it('back browser', () => {
$(navigationButton).click();
BrowserUtils.backBrowser();
BrowserUtils.back();

expect(browser.getUrl()).to.equal(sampleAppUrl);
});
Expand Down
2 changes: 1 addition & 1 deletion src/test/specs/ClickActionsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describeCommon('click', () => {
});

it('doubleClick', () => {
BrowserUtils.navigateToUrl(sampleAppUrl);
BrowserUtils.url(sampleAppUrl);
BrowserUtils.doubleClick(DOUBLE_CLICK_DIV);
$(DOUBLE_CLICK_DIV).waitForDisplayed();
assert.equal($(DOUBLE_CLICK_DIV).getText(), 'Double click');
Expand Down
8 changes: 2 additions & 6 deletions src/test/specs/DeleteCookiesSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import { describeCommon } from '../TestHelper';
/**
* wdio-allure-ts deleteCookie tests
*/
let cookie: WebDriver.Cookie;
const emptyCookie: WebDriver.Cookie = undefined;

describeCommon('DeleteCookieSpec', () => {
beforeEach(() => {
cookie = { name: TestUtils.randomString(), value: TestUtils.randomString() };
BrowserUtils.setCookie(cookie, null);
BrowserUtils.setCookies({ name: TestUtils.randomString(), value: TestUtils.randomString() }, null);
});
it('expect empty cookie', () => {
BrowserUtils.deleteCookies();
Expand All @@ -20,6 +16,6 @@ describeCommon('DeleteCookieSpec', () => {

it('delete all cookie', () => {
BrowserUtils.deleteCookies();
assert.equal(BrowserUtils.getCookies()[0], emptyCookie, 'Cookie has not been removed');
assert.equal(BrowserUtils.getCookies()[0], undefined, 'Cookie has not been removed');
});
});
2 changes: 1 addition & 1 deletion src/test/specs/DoubleClickSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describeCommon('doubleClick', () => {
.contains(`Element not visible '${hiddenElementSelector}'`);
});

it('double click disabled element', () => {
it.only('double click disabled element', () => {
const disableElementSelector: string = "//button[@id='doubleClickDisabledButton']";
expect(() => BrowserUtils.doubleClick(disableElementSelector))
.to.throw(Error)
Expand Down
16 changes: 5 additions & 11 deletions src/test/specs/DragAndDropSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ const ELEMENT: string = '#draggedSlider';
const TARGET: string = '#staticSlider';
const NOT_EXISTING_ELEMENT: string = '//*[@id="NotExistingElement_qweqwe"]';

let beforeDragLocation: WebdriverIO.DragAndDropCoordinate;
let afterDragLocation: WebdriverIO.DragAndDropCoordinate;

/**
* wdio-allure-ts drag and drop element
*/
describeCommon('dragAndDrop', () => {
it('drag and drop to coordinate', () => {
beforeDragLocation = BrowserUtils.getElementLocation(ELEMENT);
const beforeDragLocation = BrowserUtils.getLocation(ELEMENT);
BrowserUtils.dragAndDrop(ELEMENT, { x: 5, y: 0 });
afterDragLocation = BrowserUtils.getElementLocation(ELEMENT);
const afterDragLocation = BrowserUtils.getLocation(ELEMENT);
assert.isTrue(afterDragLocation.x > beforeDragLocation.x, 'Element position was not changed');
});
it('drag and drop to element', () => {
const delta: number = 10;
beforeDragLocation = BrowserUtils.getElementLocation(TARGET);
const beforeDragLocation = BrowserUtils.getLocation(TARGET);
BrowserUtils.dragAndDrop(ELEMENT, TARGET);
afterDragLocation = BrowserUtils.getElementLocation(ELEMENT);
const afterDragLocation = BrowserUtils.getLocation(ELEMENT);
assert.isTrue(
Math.abs(beforeDragLocation.x - afterDragLocation.x) < delta,
'Element was not dragged toward the target element'
Expand All @@ -42,9 +39,6 @@ describeCommon('dragAndDrop', () => {
.contains(`Failed to drag and drop ${ELEMENT} to`);
});
it('drag and drop to non existing element', () => {
expect(() => BrowserUtils.dragAndDrop(ELEMENT, NOT_EXISTING_ELEMENT))
.to.throw(Error)
.with.property('message')
.contains('Element not exist');
expect(() => BrowserUtils.dragAndDrop(ELEMENT, NOT_EXISTING_ELEMENT)).to.throw(Error);
});
});
10 changes: 5 additions & 5 deletions src/test/specs/ExecuteScriptSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { BrowserUtils } from '../..';
import { describeCommon } from '../TestHelper';

/**
* executeScript
* execute
*/
describeCommon('executeScript', () => {
describeCommon('execute', () => {
it('successful execution', () => {
const script: string = " document.getElementById('executeScriptButtonId').click()";
expect(() => BrowserUtils.executeScript(script)).to.not.throw(Error);
expect(() => BrowserUtils.execute(script)).to.not.throw(Error);

const textDivSelector: string = "//*[@id='ExecuteScript']//*[@id='executeScriptDynamicText']";
expect($(textDivSelector).getText()).to.be.eqls('Cloudinary still rules!', 'script execution failed');
Expand All @@ -17,13 +17,13 @@ describeCommon('executeScript', () => {
it('get string result', () => {
const pageTitle = 'HTML Sandbox';
const script: string = 'return document.title';
const currPageTitle = BrowserUtils.executeScript(script);
const currPageTitle = BrowserUtils.execute(script);
expect(currPageTitle).to.be.eqls(pageTitle);
});

it('failing execution', () => {
const script: string = 'not a script';
expect(() => BrowserUtils.executeScript(script))
expect(() => BrowserUtils.execute(script))
.to.throw(Error)
.with.property('message')
.contains(`Failed to execute script: ${script}`);
Expand Down
8 changes: 4 additions & 4 deletions src/test/specs/ExpectAlertTextSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import { describeCommon } from '../TestHelper';
const TEST_FIELD_SELECTOR: string = "//*[@id='ExpectAlertText']";
const TRIGGER_ALERT_BUTTON_SELECTOR: string = `${TEST_FIELD_SELECTOR}//button[@id='ExpectAlertTextTriggerAlert']`;

describeCommon('expectAlertText', () => {
describeCommon('waitForAlertText', () => {
beforeEach(() => {
browser.refresh();
});
it('correct text', () => {
$(TRIGGER_ALERT_BUTTON_SELECTOR).click();
expect(() => BrowserUtils.expectAlertText('Hello! I am an alert box!')).to.not.throw();
expect(() => BrowserUtils.waitForAlertText('Hello! I am an alert box!')).to.not.throw();
});
it('incorrect text', () => {
$(TRIGGER_ALERT_BUTTON_SELECTOR).click();
expect(() => BrowserUtils.expectAlertText('Hello! I am not alert box!'))
expect(() => BrowserUtils.waitForAlertText('Hello! I am not alert box!'))
.to.throw(Error)
.with.property('message')
.contains("Incorrect alert's text or alert not found.");
});

it('no alert', () => {
expect(() => BrowserUtils.expectAlertText('Hello! I am an alert box!'))
expect(() => BrowserUtils.waitForAlertText('Hello! I am an alert box!'))
.to.throw(Error)
.with.property('message')
.contains("Incorrect alert's text or alert not found.");
Expand Down
12 changes: 6 additions & 6 deletions src/test/specs/ExpectAttributeValueSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ const CORRECT_ATTRIBUTE_VALUE: string = 'hello world';
const INCORRECT_ATTRIBUTE_VALUE: string = 'hello hello world';

/**
* wdio-allure-ts expectAttributeValueSpec
* wdio-allure-ts waitForAttributeValueSpec
*/
describeCommon('expectAttributeValue', () => {
describeCommon('waitForAttributeValue', () => {
it('correct value', () => {
expect(() =>
BrowserUtils.expectAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, CORRECT_ATTRIBUTE_VALUE)
BrowserUtils.waitForAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, CORRECT_ATTRIBUTE_VALUE)
).to.not.throw(Error);
});

it('incorrect value', () => {
expect(() => BrowserUtils.expectAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE))
expect(() => BrowserUtils.waitForAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE))
.to.throw(Error)
.with.property('message')
.contains(`Incorrect attribute`);
});
it('incorrect selector', () => {
expect(() => BrowserUtils.expectAttributeValue(INCORRECT_SELECTOR, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE))
expect(() => BrowserUtils.waitForAttributeValue(INCORRECT_SELECTOR, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE))
.to.throw(Error)
.with.property('message')
.contains(`Incorrect attribute`);
});
it('incorrect attribute', () => {
expect(() =>
BrowserUtils.expectAttributeValue(INCORRECT_SELECTOR, INCORRECT_ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE)
BrowserUtils.waitForAttributeValue(INCORRECT_SELECTOR, INCORRECT_ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE)
)
.to.throw(Error)
.with.property('message')
Expand Down
8 changes: 4 additions & 4 deletions src/test/specs/ExpectCurrentUrlSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { describeCommon, sampleAppUrl } from '../TestHelper';

const CLOUDINARY_URL: string = 'https://cloudinary.com';
/**
* wdio-allure-ts ExpectCurrentUrlSpec
* wdio-allure-ts waitForUrl
*/
describeCommon('expectCurrentUrl', () => {
describeCommon('waitForUrl', () => {
it('correct url', () => {
expect(() => BrowserUtils.expectCurrentUrl(sampleAppUrl)).to.not.throw(Error);
expect(() => BrowserUtils.waitForUrl(sampleAppUrl)).to.not.throw(Error);
});

it('incorrect url', () => {
expect(() => BrowserUtils.expectCurrentUrl(CLOUDINARY_URL))
expect(() => BrowserUtils.waitForUrl(CLOUDINARY_URL))
.to.throw(Error)
.with.property('message')
.equal(`Url not as expected '${CLOUDINARY_URL}'`);
Expand Down
17 changes: 7 additions & 10 deletions src/test/specs/ExpectNoAttributeValueSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,31 @@ const EMPTY_DIV: string = '//*[@id="formsWithoutAttribute"]//*[@id="noAttDiv"]';
describeCommon('expectNoAttributeValue', () => {
it("Doesn't contains value", () => {
expect(() =>
BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCent')
BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCent', true)
).to.not.throw(Error);
});

it('Contains word substring', () => {
expect(() =>
BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenterrr')
BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenterrr', true)
).to.not.throw(Error);
});

it('Exact match error thrown', () => {
expect(() => BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenter'))
expect(() => BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenter', true))
.to.throw(Error)
.with.property('message')
.contains('Incorrect attribute');
});

it('Element not exists', () => {
BrowserUtils.navigateToUrl(sampleAppUrl);
expect(() => BrowserUtils.expectNoAttributeValue('//NotExist', 'method', 'post'))
.to.throw(Error)
.with.property('message')
.contains('Element not exist');
BrowserUtils.url(sampleAppUrl);
expect(() => BrowserUtils.waitForAttributeValue('//NotExist', 'method', 'post', true)).to.throw(Error);
});

it('Attribute not exists', () => {
BrowserUtils.navigateToUrl(sampleAppUrl);
expect(() => BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'NotExist', 'post'))
BrowserUtils.url(sampleAppUrl);
expect(() => BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'NotExist', 'post', true))
.to.throw(Error)
.with.property('message')
.contains('Incorrect attribute');
Expand Down
17 changes: 7 additions & 10 deletions src/test/specs/ExpectNumberOfElementsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,30 @@ import { describeCommon } from '../TestHelper';
const SELECTION_BOX: string = '//*[@id="selection_list"]';
const LIST_ITEM: string = '//option';

describeCommon('expectNumberOfElements', () => {
describeCommon('waitForNumberOfElements', () => {
it('Expect number of elements equals', () => {
expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 4)).to.not.throw(Error);
expect(() => BrowserUtils.waitForNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 4)).to.not.throw(Error);
});

it('Expect number of elements not equals', () => {
expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 3))
expect(() => BrowserUtils.waitForNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 3))
.to.throw(Error)
.with.property('message')
.contains(`not equal`);
});
it('Expect 0 elements equals', () => {
expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}`, 0))
.to.throw(Error)
.with.property('message')
.contains(`element not visible`);
expect(() => BrowserUtils.waitForNumberOfElements("//div[@data-test='not-existing']", 0)).to.not.throw(Error);
});

it('Expect 0 elements not equals', () => {
expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 0))
expect(() => BrowserUtils.waitForNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 0))
.to.throw(Error)
.with.property('message')
.contains(`element not visible`);
.contains(`still existing`);
});

it("Expect number of elements, element doesn't exists", () => {
expect(() => BrowserUtils.expectNumberOfElements(`//notExists`, 4))
expect(() => BrowserUtils.waitForNumberOfElements(`//notExists`, 4))
.to.throw(Error)
.with.property('message')
.contains(`waitUntil condition timed out`);
Expand Down
16 changes: 8 additions & 8 deletions src/test/specs/ExpectTextSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const DYNAMIC_TEXT_SELECTOR: string = `${TEST_FIELD_SELECTOR}//*[@id='dynamic_te
const HIDDEN_TEXT_SELECTOR: string = `${TEST_FIELD_SELECTOR}//*[@id='hidden_text']`;
const CHANGE_TEXT_BUTTON_SELECTOR: string = `${TEST_FIELD_SELECTOR}//button[@id='update_text']`;
/**
* wdio-allure-ts expectedText tests
* wdio-allure-ts waitForText tests
*/
describeCommon('expectText', () => {
describeCommon('waitForText', () => {
it('correct text', () => {
expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!')).to.not.throw();
expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!')).to.not.throw();
});

it('hidden text', () => {
expect(() => BrowserUtils.expectText(HIDDEN_TEXT_SELECTOR, 'Cloudinary rules!'))
expect(() => BrowserUtils.waitForText(HIDDEN_TEXT_SELECTOR, 'Cloudinary rules!'))
.to.throw()
.with.property('message')
.contains('Element not visible');
Expand All @@ -26,25 +26,25 @@ describeCommon('expectText', () => {
$(CHANGE_TEXT_BUTTON_SELECTOR).waitForDisplayed();

$(CHANGE_TEXT_BUTTON_SELECTOR).click();
BrowserUtils.expectText(DYNAMIC_TEXT_SELECTOR, 'Cloudinary still rules!');
BrowserUtils.waitForText(DYNAMIC_TEXT_SELECTOR, 'Cloudinary still rules!');
});

it('fail on case sensitive', () => {
expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'cloudinary rules!'))
expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'cloudinary rules!'))
.to.throw(Error)
.with.property('message')
.contains('waitUntil condition timed out');
});

it('fail on spaces', () => {
expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!'))
expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!'))
.to.throw(Error)
.with.property('message')
.contains('waitUntil condition timed out');
});

it('fail on wrong text', () => {
expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'Cloudinary not rules!'))
expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'Cloudinary not rules!'))
.to.throw(Error)
.with.property('message')
.contains('waitUntil condition timed out');
Expand Down
Loading

0 comments on commit e594ee7

Please sign in to comment.