Я только начал использовать Cucumber с селеном. Пожалуйста, игнорируйте, если есть какие-либо ошибки с моей стороны. У меня есть 2 сценария. 1. Войдите как пользователь А и добавьте профиль. 2. Войдите в систему как пользователь B и подтвердите профиль.
У меня есть один и тот же файл для двух сценариев. Файл функции показан ниже,
@Login
Scenario Outline: Login into application with valid credentials
Given enter '<Username>' and '<Password>'
When clicking submit button
Then System should logged into application
Examples:
|Username|Password |
|aaaa |aaa@123 |
@LoginApprover
Scenario Outline: Login as Approver application with valid credentials
Given enter approver credentials '<AppUsername>' and '<AppPassword>'
When clicking login button
Then Approver should be logged into application
Examples:
|AppUsername|AppPassword |
|bbb |bbb@123 |
Мой класс объекта страницы
public class Login extends AllDetails {
public Login(WebDriver dr) {
driver = dr;
}
private final By USERNAME = By.cssSelector("#wwww");
private final By PASSWORD = By.cssSelector("#eeee");
private final By SIGNIN_BUTTON = By.cssSelector("#login");
private final By ALERTMSG = By.xpath("//*[@class='alert alert-danger']/p");
public void enterUsername(String userName) {
waitUntilElementIsDisplayedOnScreen(USERNAME);
sendKeys(USERNAME, userName);
}
public void enterPassword(String password) {
waitUntilElementIsDisplayedOnScreen(PASSWORD);
sendKeys(PASSWORD, password);
}
public void clickSignInButton() {
click(SIGNIN_BUTTON);
}
public void alertmessageVerification(String msg) {
try {
String mesg = driver.findElement(ALERTMSG)
.getAttribute("innerText");
Assert.assertEquals("Following message prompted successfully", msg,
message);
} catch (Exception e) {
System.out.println(String.format(
"Following Message is not prompted ", msg));
}
}
Мой класс определения шага,
public class LoginDefn extends details{
@Given("^enter '(.*)' and '(.*)'$")
public void enter_username_and_password(String username, String password)
throws Throwable {
lp=getPageFactoryObject(Login.class);
lp.enterUsername(username);
lp.enterPassword(password);
}
@When("^clicking submit button$")
public void clicking_submit_button() throws Throwable {
lp.clickSignInButton();
}
@Then("^System should logged into application$")
public void system_should_logged_into_application() throws Throwable {
}
@Then("^System should not logged into application and prompt msg as(.*)$")
public void system_should_not_logged_into_application_and_prompt_msg_as_Invalid_username_and_password(String msg) throws Throwable {
Thread.sleep(2000);
lp.alertmessageVerification(msg);
//lp.clearusernameandpassword();
}
@Given("^enter approver credentials '(.*)' and '(.*)'$")
public void enter_approver_credentials_and_(String appusername, String apppassword) throws Throwable {
lp.enterUsername(appusername);
lp.enterPassword(apppassword);
}
@When("^clicking login button$")
public void clicking_login_button() throws Throwable {
lp.clickSignInButton();
}
@Then("^Approver should be logged into application$")
public void approver_should_be_logged_into_application() throws Throwable {
//do nothing
}
} Мой класс запуска тестов
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@CucumberOptions(features = { "src\\test\\java\\com\\Features\\" }, glue =
{"definitions" }, plugin = {
"pretty", "json:target/cucumber.json" }, tags =
{"@Login,@LoginApprover"}, monochrome = true)
@RunWith(Cucumber.class)
Кто-нибудь, пожалуйста, помогите мне решить эту проблему.