В jQuL Cucumber, если у нас есть несколько сценариев и есть ли возможность выполнить весь сценарий в одном экземпляре. Я имею в виду открытие браузера один раз и выполнение всех сценариев, а не открытие и закрытие браузера для каждого сценария.Cucumber Jvm Before All Сценарий
Я пробовал с BeforeAll в файле hooks, но его бросая Nullpointer Exception.
Здесь мой код. Мне нужно перейти к URL-адресу, войти в систему с учетными данными и выполнить оба сценария в одном экземпляре.
MaharaTest.feature
Feature: MaharaTest
Scenario: Creating Profile
Given I navigate to Content Tab
And I enter firstname
And I enter lastname
And I click save profile
Then I see profile saved successful message
Scenario: Creating Profile
Given I navigate to Portfolio Tab
And I click create page
And I enter page title
And I click save page
Then I see page saved successful message
MaharaTest.java
public class MaharaTest {
public WebDriver driver;
public MaharaTest() {
driver = Hooks.driver;
}
@Given("^I navigate to Content Tab$")
public void navigate_to_content() {
driver.findElement(By.linkText("Content")).click();
}
@And("^I enter firstname$")
public void enter_firstname() {
driver.findElement(By.id("profileform_firstname")).clear();
driver.findElement(By.id("profileform_firstname")).sendKeys("Test");
}
@And("^I enter lastname$")
public void enter_lastname() {
driver.findElement(By.id("profileform_lastname")).clear();
driver.findElement(By.id("profileform_lastname")).sendKeys("User");
}
@And("^I click save profile$")
public void click_save() {
driver.findElement(By.id("profileform_submit")).click();
}
@Then("^I see profile saved successful message$")
public void profile_success_message() {
assertEquals("Profile saved successfully",
driver.findElement(By.className("alert-success")).getText());
}
@Given("^I navigate to Portfolio Tab$")
public void navigate_to_portfolio() {
driver.findElement(By.linkText("Portfolio")).click();
}
@And("^I click create page$")
public void create_page() {
driver.findElement(By.id("createview_submit")).click();
}
@And("^I enter page title$")
public void enter_page_title() {
driver.findElement(By.id("editview_title")).clear();
driver.findElement(By.id("editview_title")).sendKeys("Test_Profile");
}
@And("^I click save page$")
public void click_save_page() {
driver.findElement(By.id("editview_submit")).click();
}
@Then("^I see page saved successful message$")
public void page_success_message() {
assertEquals("Page saved successfully",
driver.findElement(By.className("alert-success")).getText());
}
}
Hooks.java
public class Hooks {
public static WebDriver driver;
@Before
public void openBrowser() throws MalformedURLException {
System.out.println("Called openBrowser");
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://demo.mahara.org/");
driver.findElement(By.id("login_login_username")).sendKeys("student1");
driver.findElement(By.id("login_login_password")).sendKeys("Testing1");
driver.findElement(By.id("login_submit")).click();
}
@After
public void embedScreenshot(Scenario scenario) {
if (scenario.isFailed()) {
try {
scenario.write("Current Page URL is " + driver.getCurrentUrl());
byte[] screenshot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
System.err.println(somePlatformsDontSupportScreenshots
.getMessage());
}
}
driver.quit();
}
}
Спасибо за ваши данные. Но опять же, если мне нужно выполнить второй сценарий i.e Создать страницу портфолио, он запустит новое окно только прямо, вместо того, чтобы работать в том же браузере, запущенном для 1-го сценария, как это преодолеть? –