promod-system
v3.3.0-beta-8
Published
Library promod condition waitings
Downloads
6,847
Maintainers
Readme
Usage. promod example.
Waiters
import { seleniumWD } from 'promod';
import { createBrowserWaiters, createElementWaiters } from 'promod-system';
const { browser, $ } = seleniumWD;
;(async () => {
await getSeleniumDriver({seleniumAddress: 'http://localhost:4444/wd/hub'}, browser);
const browserWaiters = createBrowserWaiters(browser);
const elementWaiters = createElementWaiters();
const documentBody = $('body');
await browser.get('https://www.npmjs.com/');
await browserWaiters.waitForTabTitleIncludes('promod', {timeout: 10_000});
await elementWaiters.waitForTextIncludes(documentBody, 'promod' {timeout: 10_000});
})();
Core
import { waitForCondition } from 'sat-utils';
import { seleniumWD } from 'promod';
import { PromodSystemStructure } from 'promod-system';
import type { PromodElementType } from 'promod/built/interface';
const timeouts = {
s: 5000,
m: 10000,
l: 15000,
xl: 25000,
}
class BaseElement extends PromodSystemElement<PromodElementType> {
constructor(locator: string, name: string, rootElement) {
super(locator, name, rootElement);
}
/**
* @info
* this method should be overridden,
* method will be execute to wait visibility before next base methods
* sendKeys, get, action
* ! for isDisplayed method waitLoadedState will not be executed.
*/
async waitLoadedState() {
await waitForCondition(async () => this.rootElement.isDisplayed(), {
message: `Element ${this.identifier} with root selector ${this.rootLocator}
should become visible during ${timeouts.l} ms.`
timeout: timeouts.l
});
}
/**
* @info
* this method should be overridden,
* method will be execute inside sendKeys method
* depends on base library/framework specific
*/
async baseSendKeys(value): Promise<void> {
await this.rootElement.sendKeys(value);
}
/**
* @info
* this method should be overridden,
* method will be execute inside get method
* depends on base library/framework specific
*/
async baseGetData(): Promise<{ background: any; value: any }> {
return browser.executeScript(() => {
const background = arguments[0].style.background;
const value = arguments[0].value;
const rect = arguments[0].getBoundingClientRect();
const text = arguments[0].innerText.trim()
return {background, value, rect, text}
}, this.rootElement.getEngineElement());
}
}
class BaseFragment extends PromodSystemStructure {
constructor(locator: string, name: string, rootElement: PromodElementType) {
super(locator, name, rootElement);
}
init(locator: string, name: string, Child: new (...args) => any, ...rest) {
return new Child(locator, name, this.rootElement.$(locator), ...rest);
}
initCollection(locator: string, name: string, Collection: new (...args) => any, Child: new (...args) => any) {
return new Collection(locator, name, this.rootElement.$$(locator), Child);
}
/**
* @info
* this method should be overridden, it will be execute to wait visibility before next base methods
* sendKeys, get, action
* ! for isDisplayed method waitLoadedState will not be executed.
*/
async waitLoadedState() {
await waitForCondition(async () => this.rootElement.isDisplayed(), {
message: `Fragment ${this.identifier} with root selector ${this.rootLocator}
should become visible during ${timeouts.l} ms.`
timeout: timeouts.l
});
}
}
class BasePage extends PromodSystemStructure {
constructor(locator: string, pageName: string) {
super(locator, structureName, $(locator));
}
init(locator: string, name: string, Child: new (...args) => any) {
return new Child(locator, name, this.rootElement.$(locator));
}
initCollection(locator: string, name: string, Collection: new (...args) => any, Child: new (...args) => any) {
return new Collection(locator, name, this.rootElement.$$(locator), Child);
}
/**
* @info
* this method should be overridden,
* method will be execute to wait visibility before next base methods
* sendKeys, get, action
* ! for isDisplayed method waitLoadedState will not be executed.
*/
async waitLoadedState() {
await waitForCondition(async () => this.rootElement.isDisplayed(), {
message: `Page ${this.identifier} with root selector ${this.rootLocator}
should become visible during ${timeouts.l} ms.`
timeout: timeouts.l
});
}
}
Improvement/new features plan
- [x] Fix hardcoded values
- [x] Generate get random flows for several fields
- [ ] Config validation
- [ ] Logging
- [ ] Error messages
- [x] Generate config
baseElementsActionsDescription
part based on base elements library - [ ] Generate base library
- [ ] Generate project example
- [ ] Вepth level flow generation