Каждый раз, когда выполняется значение Контур сценария, браузер загружается снова - PullRequest
1 голос
/ 02 марта 2020

Когда я предоставляю неверный телефон три раза, при каждом вызове значения загружается браузер. Я использовал Background, но пока не смог. Спасибо

Файл функции:

Functionality: Validate the creation of a new Gmail account.

Background:
  Given that I'm on the gmail main page.

Scenario Scheme: Register user with invalid phone
 When I create a new account with phone "" different from my country.
 Then I can see the message "" in an invalid format.

Examples:

| phone           | message |  
| +374 981929578  | This phone number format is not valid. Check the country and the number. |  
| +61 981929578   | This phone number format is not valid. Check the country and the number. |
| +36 981929578   | This phone number format is not valid. Check the country and the number.

Код:

import cucumber.api.java.pt.When;
import cucumber.api.java.pt.Then;
import cucumber.api.java.pt.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

    public class newUser {

    WebDriver driver;

    @Given("^that I am on the main page of gmail\\.$")
    public void that_i_am_on_the_main__page_of_gmail() throws Throwable

      {
        System.setProperty("webdriver.chrome.driver","C:\\Browsers\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.gmail.com");  
      }

    @When("^I create a new account with phone \ "([^ \"] *) \ "different from my Country \\.$")
    public void i_create_a_new_account_with_differente_phone_from_my_country(String phone) throws Throwable {

          driver.findElement(By.xpath("//span[contains(text(),'create account ')]")).click();
          Thread.sleep(2000);
          driver.findElement(By.xpath("//div[contains(text(),'to me')]")).click();
          Thread.sleep(2000);
          driver.findElement(By.id("firstName")).sendKeys("Jhon");
          driver.findElement(By.id("lastName")).sendKeys("Automation");
          driver.findElement(By.id("username")).sendKeys("jhonautomation2020@gmail.com");


          driver.findElement(By.name("Passwd")).sendKeys("automation2020");
          driver.findElement(By.name("ConfirmPasswd")).sendKeys("automation2020");


          driver.findElement(By.id("accountDetailsNext")).click();
          Thread.sleep(3000);


          driver.findElement(By.id("phoneNumberId")).sendKeys(phone);
          driver.findElement(By.id("gradsIdvPhoneNext")).click();

        }

1 Ответ

1 голос
/ 04 марта 2020

Scenario outline - может использоваться для запуска одного и того же сценария несколько раз с разными значениями, сценарий выполняется один раз для каждой строки, и каждая строка рассматривается как сценарий

Background - представляет общий шаг, который будет выполняться для каждого сценария

Что вы можете сделать, это проверить, уже создан ли драйвер, и повторно использовать его, но помните, что это не очень хорошая практика.

в качестве улучшений следует переместить запуск / закрытие драйвера за пределы шагов / сценария, используя hooks, а каждый шаг делать только то, что он говорит.

...