Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await reloadAmount.sendKeys(`${card.reloadAmount}`);
await driver.executeScript('document.querySelector("#asv-manual-reload-amount").blur();');
// Try to submit the reload.
const submitButton = await driver.findElement(By.id('form-submit-button'));
try {
await driver.wait(until.elementTextIs(submitButton, `Reload $${card.reloadAmount.toFixed(2)}`), 10000);
await submitButton.click();
await driver.wait(until.titleIs('Thank you for reloading your balance'), 10000);
return;
} catch (error) {}
// If the reload fails, we must confirm the card number.
const confirmation = await driver.findElement(By.xpath(`//input[@placeholder='ending in ${card.lastFour}']`));
await driver.wait(until.elementIsVisible(confirmation));
await confirmation.sendKeys(card.cardNumber);
const confirmationButtons = await driver.findElements(By.xpath('//button[contains(.,\'Confirm Card\')]'));
for (let i = 0; i < confirmationButtons.length; i++) {
if (await confirmationButtons[i].isDisplayed()) {
await confirmationButtons[i].click();
}
}
// Manual wait time to allow for the confirmation to finish.
await sleep(5000);
try {
await driver.wait(until.elementTextIs(submitButton, `Reload $${card.reloadAmount.toFixed(2)}`), 10000);
await submitButton.click();
await driver.wait(until.titleIs('Thank you for reloading your balance'), 10000);
private async makePurchase(card: Card): Promise
{
// A driver alias so the code isn't *as* unwieldy
const driver: ThenableWebDriver = this.browser.driver;
if (card.reloadAmount < 1)
{
logger.info(`Reload amount ${card.reloadAmount} for ${card.description} is below site minimum; skipping card.`);
return;
}
const paymentMethodLocator: Locator = By.css(".payoptions-dropdown .dropdown__knob");
const paymentMethodElement: WebElement = await driver.wait(until.elementLocated(paymentMethodLocator));
await driver.wait(until.elementIsVisible(paymentMethodElement))
.click();
try
{
const cardDropdown: WebElement =
await driver.findElement(By.xpath(`//li[contains(.,\'${card.shortDescription}\')]`));
await cardDropdown.click();
}
catch
{
// If we can't find the card, enter a new card
await driver.findElement(By.xpath("//li[contains(.,\'Add credit/debit card\')]"))
.click();
const cardNumberElement: WebElement = await driver.findElement(By.id("cardInputField"));
await cardNumberElement.sendKeys(`${card.cardNumber}`);
async findByLocator(locator) {
await this.driver.wait(until.elementLocated(locator), 10000, 'Looking for element: ' + locator);
const element = await this.driver.findElement(locator);
await this.driver.wait(until.elementIsVisible(element), 10000, 'Waiting for element to become visible: ' + locator);
return element;
}
async getSearchPageUrl() {
const selector = by.css( 'iframe.iframe-preview' );
await this.driver.wait(
until.elementLocated( selector ),
this.explicitWaitMS,
'Could not locate the search results'
);
const iframe = await this.driver.findElement( selector );
await this.driver.wait(
until.elementIsVisible( iframe ),
this.explicitWaitMS,
'Could not see search results'
);
return await iframe.getAttribute( 'src' );
}
}
async wait(timeout: number = 5000): Promise {
await this.getDriver().wait(until.elementIsVisible(this), timeout);
return this;
}
async waitElelmentIsVisible(xpath, timeout) {
const el = await this.driver.wait(
until.elementLocated(By.xpath(xpath)),
timeout
)
await this.driver.wait(until.elementIsVisible(el), timeout);
}
return terminal.isDisplayed().then((visible) => {
if (!visible) {
this.driver.findElement(dom.terminal.button).click();
return this.driver.wait(until.elementIsVisible(terminal), timeout);
}
return Promise.resolve();
});
}
public async waitVisibility(elementLocator: By, timeout: number = TestConstants.TS_SELENIUM_DEFAULT_TIMEOUT): Promise {
const attempts: number = TestConstants.TS_SELENIUM_DEFAULT_ATTEMPTS;
const polling: number = TestConstants.TS_SELENIUM_DEFAULT_POLLING;
Logger.trace(`DriverHelper.waitVisibility ${elementLocator}`);
for (let i = 0; i < attempts; i++) {
const webElement: WebElement = await this.driver.wait(until.elementLocated(elementLocator), timeout);
try {
const visibleWebElement = await this.driver.wait(until.elementIsVisible(webElement), timeout);
return visibleWebElement;
} catch (err) {
if (err instanceof error.StaleElementReferenceError) {
await this.wait(polling);
continue;
}
throw err;
}
}
throw new error.TimeoutError(`Exceeded maximum visibility checkings attempts, problems with 'StaleElementReferenceError' of '${elementLocator}' element`);
}
module.exports.generateLinksNoCohorts = async function (driver, count) {
const linksCountField = await driver.findElement(By.id('participants-count-' + UNASSIGNED_COHORT));
const submitButton = await driver.findElement(By.id('participants-submit-' + UNASSIGNED_COHORT));
const linksArea = await driver.findElement(By.id('participants-new-' + UNASSIGNED_COHORT));
await driver.wait(until.elementIsVisible(submitButton));
await driver.wait(until.elementIsEnabled(submitButton));
await linksCountField.sendKeys(count.toString());
submitButton.click();
await helpers.conditionOrAlertError(driver, until.elementIsVisible(linksArea));
var links = await linksArea.getText();
links = links.trim().split('\n').map(link => link.trim());
assert.equal(links.length, count, 'Incorrect participation links count');
return links;
};
test.it('Can cancel out of adding a new story', function() {
var addButton = dr.findElement({ css: '.addStory' });
var bubble = addButton
.findElement({ xpath: '../..' })
.findElement({ css: '.bubble '});
addButton.click();
dr.wait(until.elementIsVisible(bubble));
dr.findElement({ css: '.cancelAdd' }).click();
dr.wait(until.elementIsNotVisible(bubble));
});