Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { binding, given, when, then } from "cucumber-tsflow";
import { CallbackStepDefinition } from 'cucumber';
import { ForgotPasswordPageObject } from './forgotPassword.page';
import { LoginPageObject } from '../login';
import { AuthenticationPageObject } from '../authentication.page';
@binding()
class ForgotPasswordSteps {
private authenticationModule = new AuthenticationPageObject();
private loginPageObject = new LoginPageObject();
private forgotPasswordPageObject = new ForgotPasswordPageObject();
@given(/^user clicks the forgot password link$/)
private givenUserClicksTheForgotPasswordLink(callback: CallbackStepDefinition) {
this.authenticationModule.goToLoginPage();
this.loginPageObject.navigateToForgotPasswordPage();
callback();
};
@given(/^'(.*)' is the user email used in the forgot password form$/)
private givenUserEmail(email: string, callback: CallbackStepDefinition) {
this.forgotPasswordPageObject.setEmail(email);
callback();
};
@when(/^submitting the forgot password form$/)
private whenSubmitForm(callback: CallbackStepDefinition) {
this.forgotPasswordPageObject.submitForm();
callback();
private registerPageObject = new RegisterPageObject();
@given(/^user clicks the register link$/)
private givenUserClicksTheLoginLink(callback: CallbackStepDefinition) {
this.authenticationModule.goToLoginPage();
this.loginPageObject.navigateToRegisterPage();
callback();
};
@given(/^'(.*)' is the user name used in the register form$/)
private givenUsername(name: string, callback: CallbackStepDefinition) {
this.registerPageObject.setName(name);
callback();
};
@given(/^'(.*)' is the user email used in the register form$/)
private givenUserEmail(email: string, callback: CallbackStepDefinition) {
this.registerPageObject.setEmail(email);
callback();
};
@given(/^'(.*)' is the provided password used in the register form$/)
private givenPassword(password: string, callback: CallbackStepDefinition) {
this.registerPageObject.setPassword(password);
callback();
};
@given(/^'(.*)' is the repeated password used in the register form/)
private givenRepeatPassword(repeatPassword: string, callback: CallbackStepDefinition) {
this.registerPageObject.setRepeatPassword(repeatPassword);
callback();
};
@given(/^I read the content of element "([^"]*)" and store in variable "([^"]*)" as a "([^"]*)"$/, null, 60 * 1000)
public readContentAndStoreInVariable(
elementKey: string,
variableKey: string,
variableType: string
) {
return this.readContentWithSelectionAndStoreInVariable(
elementKey,
null,
null,
variableKey,
variableType
);
}
@given(/^I read the content of element "([^"]*)" with the "([^"]*)" of "([^"]*)" and store in variable "([^"]*)" as a "([^"]*)"$/, null, 60 * 1000)
public readContentWithSelectionAndStoreInVariable(
elementKey: string,
selectionMethod: string,
selectionValue: string,
variableKey: string,
variableType: string
) {
let elementToStore = this.getWebElement(
elementKey,
selectionMethod,
selectionValue
);
return assert.eventually.equal(
elementToStore.getText().then(
(value: string) => {
this.variableService.addVariable(variableKey, variableType, value);
}
@given(/^I Subtract variable "([^"]*)" from "([^"]*)" and store in "([^"]*)"$/, null, 60 * 1000)
public subTractNumericValues(variableKey1: string, variableKey2: string, newVariable: string) {
let valOne = this.getVariable(variableKey1, VariableType.Number).toNumber();
let valTwo = this.getVariable(variableKey2, VariableType.Number).toNumber();
const subtractVariables = () => {
let newVal = valOne - valTwo;
this.variableService.addVariable(newVariable, VariableType.Number, newVal.toString());
return true;
}
return assert.eventually.equal(Promise.resolve(subtractVariables()), true, 'Operation failed');
}
@given(/^I Multiply variable "([^"]*)" from "([^"]*)" and store in "([^"]*)"$/, null, 60 * 1000)
public multiplyNumericValues(variableKey1: string, variableKey2: string, newVariable: string) {
let valOne = this.getVariable(variableKey1, VariableType.Number).toNumber();
let valTwo = this.getVariable(variableKey2, VariableType.Number).toNumber();
const multiplyVariables = () => {
let newVal = valOne * valTwo;
this.variableService.addVariable(newVariable, VariableType.Number, newVal.toString());
return true;
}
return assert.eventually.equal(Promise.resolve(multiplyVariables()), true, 'Operation failed');
}
@given(/^I Divide variable "([^"]*)" from "([^"]*)" and store in "([^"]*)"$/, null, 60 * 1000)
public divideNumericValues(variableKey1: string, variableKey2: string, newVariable: string) {
let valOne = this.getVariable(variableKey1, VariableType.Number).toNumber();
let valTwo = this.getVariable(variableKey2, VariableType.Number).toNumber();
let waitMils = parseInt(seconds) * 1000;
return assert.eventually.equal(
browser.driver.sleep(waitMils).then(
() => {
return waitMils;
},
(error: any) => {
throw new Error(error.message);
}
),
waitMils,
'Operation failed.'
);
}
@given(/^The content of "([^"]*)" has text "([^"]*)"$/, null, 60 * 1000)
public verifyElementText(elementKey, expectedText) {
return this.verifyElementTextWithSelectionMethod(
elementKey,
null,
null,
expectedText
);
}
@given(
/^The content of "([^"]*)" with the "([^"]*)" of "([^"]*)" has text "([^"]*)"$/,
null,
60 * 1000
)
public verifyElementTextWithSelectionMethod(
elementKey: string,
'"'
);
this.elementService.addNewElement(elementKey, webElement);
return webElement;
} else {
let webElement = this.elementService.getElementByKey(elementKey);
if (!webElement)
throw new Error(
'Element "' + elementKey + '" not found in object repository.'
);
return webElement;
}
}
@given(/^[I|i] navigate to "([^"]*)"$/, null, 160 * 1000)
@given(/[N|n]avigate to "([^"]*)"$/, null, 160 * 1000)
public navigateToUrl(url: string): void {
return assert.eventually.equal(
browser.get(url).then(
() => {
return url;
},
(error: any) => {
throw new Error(error.message);
}
),
url,
'Navigated to the wrong url.'
);
}
@given(/^[E|e]nter "([^"]*)" to the "([^"]*)"$/, null, 60 * 1000)
true,
'Operation failed.'
);
}
@given(/^Wait for "([^"]*)" to contain text "([^"]*)"$/, null, 60 * 1000)
public waitForElementToContainText(elementKey: string, targetText: string) {
return this.waitForElementToContainTextWithSelection(
elementKey,
null,
null,
targetText
);
}
@given(
/^Wait for "([^"]*)" with the "([^"]*)" of "([^"]*)" to contain text "([^"]*)"$/,
null,
60 * 1000
)
public waitForElementToContainTextWithSelection(
elementKey: string,
selectionMethod: string,
selectionValue: string,
targetText: string
) {
let elementToWait = this.getWebElement(
elementKey,
selectionMethod,
selectionValue
);
let expectedCondition = ExpectedConditions.textToBePresentInElement(
},
(error: any) => {
throw new Error(error.message);
}
),
true,
'This had better be true, eventually'
);
}
@given(/^Click on "([^"]*)"$/, null, 60 * 1000)
public clickOnElement(elementKey) {
this.clickOnElementWithSelectionMethod(elementKey, null, null);
}
@given(
/^Click on "([^"]*)" with the "([^"]*)" of "([^"]*)"$/,
null,
60 * 1000
)
public clickOnElementWithSelectionMethod(
elementKey,
selectionMethod,
selectionValue
) {
let elementToClick = this.getWebElement(
elementKey,
selectionMethod,
selectionValue
);
return assert.eventually.equal(
elementToClick.click().then(
'Navigated to the wrong url.'
);
}
@given(/^[E|e]nter "([^"]*)" to the "([^"]*)"$/, null, 60 * 1000)
@given(/^[I|i] enter "([^"]*)" to the "([^"]*)"$/, null, 60 * 1000)
public enterTextToElement(inputValue: string, elementKey: string) {
this.enterTextToElementWithSelectionMethod(
inputValue,
elementKey,
null,
null
);
}
@given(
/^I enter "([^"]*)" to the "([^"]*)" with the "([^"]*)" of "([^"]*)"$/,
null,
60 * 1000
)
public enterTextToElementWithSelectionMethod(
inputValue: string,
elementKey: string,
selectionMethod: string,
selectionValue: string
) {
let inputElement = this.getWebElement(
elementKey,
selectionMethod,
selectionValue
);
return assert.eventually.equal(
inputElement.sendKeys(inputValue).then(
() => {
return true;
},
(error: any) => {
throw new Error(error.message);
}
),
true,
'This had better be true, eventually'
);
}
@given(/^Click on "([^"]*)"$/, null, 60 * 1000)
public clickOnElement(elementKey) {
this.clickOnElementWithSelectionMethod(elementKey, null, null);
}
@given(
/^Click on "([^"]*)" with the "([^"]*)" of "([^"]*)"$/,
null,
60 * 1000
)
public clickOnElementWithSelectionMethod(
elementKey,
selectionMethod,
selectionValue
) {
let elementToClick = this.getWebElement(
elementKey,