无法将url从属性文件传递到页面对象

fzwojiic  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(172)

我正在尝试从头开始构建我的第一个框架,它基于SeleniumWebDriver,使用cucumber和java。我使用存储的url创建了config.properties,然后创建了propertiesfile类,在其中设置chromedriver并获取url,下面是代码:

package config;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesFile {

    private static String url;

    public static void main(String[] args) {
        File file = new File("./src/main/java/config/config.properties");

        FileInputStream fileInput = null;
        try {
            fileInput = new FileInputStream(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Properties prop = new Properties();

        try {
            prop.load(fileInput);
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.setProperty("webdriver.chrome.driver","./integers/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();

        driver.get(prop.getProperty("url"));
        System.out.println("url ::" + prop.getProperty("url"));

        url = prop.getProperty("url");
    }

    public static String getURL() {
        return url;
    }
}

我想将相同的url传递给page对象类,但是我有点卡住了。我在super(driver,wait)和driver.get(baseurl)上得到一个错误,返回缺少局部变量的错误bc。

package page_objects;
import config.PropertiesFile;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.WebDriverWait;

public class addingFormPage {

    public addingFormPage (WebDriver driver, WebDriverWait wait) {
        super(driver, wait);
    }

    String baseURL = PropertiesFile.getURL();

    public void openHome (){
        driver.get(baseURL);

谁能帮我解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题