Отсутствует заявление о возврате, как я могу исправить? - PullRequest
0 голосов
/ 28 мая 2020

Цель: у меня есть класс InvokeChromeTest, который я расширяю до другого класса под названием «Base» для доступа к chromedriver и data.properties. При запуске кода я получаю сообщение об ошибке:

Ошибка: (22, 3) java: отсутствует оператор возврата

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

src / test / java / loginPage / InvokeChromeTest

package loginPage;

import credentials.ProfileCredentials;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import resources.Base;

public class InvokeChromeTest extends Base {

  @Test

  public WebDriver initializeDriver() {
    driver = initializeDriver();
    driver.get(dataProperties.getProperty("url"));
    ProfileCredentials p = new ProfileCredentials(driver);
    p.getAuthorize().click();
    p.getApiKey().sendKeys("testKey");
    p.getAuthCred().click();
    p.getCloseAuth().click();

  }

  @AfterTest
  public void teardown() {
    driver.close();
  }

}

src / main / java / ресурсы / База

package resources;

import io.github.bonigarcia.wdm.WebDriverManager;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Base {

  public WebDriver driver;
  protected Properties dataProperties;

  public WebDriver initializeDriver() {
    // Create global property file
    dataProperties = new Properties();
    InputStream dataPropertiesInputStream = null;
    try{
      dataPropertiesInputStream = getClass().getClassLoader().getResourceAsStream("data.properties");
      dataProperties.load(dataPropertiesInputStream);
    } catch (IOException e) {
      e.printStackTrace();
    }
    String browserName = dataProperties.getProperty("browser");
    System.out.println(browserName);

    if (browserName.equals("chrome")) {
      WebDriverManager.chromedriver().setup();
      driver = new ChromeDriver();
    } else if (browserName.equals("firefox")) {
      WebDriverManager.firefoxdriver().setup();
      driver = new FirefoxDriver();
    }
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    return driver;
  }

}

src / main / java / credentials / ProfileCredentials

package credentials;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ProfileCredentials {

  WebDriver driver;


  public ProfileCredentials(WebDriver driver) {
    this.driver = driver;
  }

  private By authorize = By.xpath("//button[@class='btn authorize unlocked']");
  private By apikey = By.xpath("//div[@class='wrapper']//section//input");
  private By authorizecred = By.xpath("//button[@class='btn modal-btn auth authorize button']");
  private By closeauth = By.xpath("//button[@class='btn modal-btn auth btn-done button']");

  public WebElement getAuthorize() {
    return driver.findElement(authorize);
  }

  public WebElement getApiKey() {
    return driver.findElement(apikey);
  }

  public WebElement getAuthCred() {
    return driver.findElement(authorizecred);
  }

  public WebElement getCloseAuth() {
    return driver.findElement(closeauth);
  }
}

1 Ответ

0 голосов
/ 28 мая 2020

Я разобрался в проблеме. «Base» и «InvokeChromeTest» имели одинаковое имя метода. Вот почему он был рекурсивным.

...