Java Can';t调用使其成为静态或添加无参数错误消息don';我不懂逻辑

Java Can';t调用使其成为静态或添加无参数错误消息don';我不懂逻辑,java,selenium-webdriver,Java,Selenium Webdriver,因此,我尝试使用@test注释调用一个测试,并为我需要的变量调用一个属性文件。我试图尽可能具体,这样你们就可以了解到底发生了什么,但问题是我不明白我收到的错误如何影响我正在测试的内容。我会尽力解释清楚 package dataSheet; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOExcep

因此,我尝试使用@test注释调用一个测试,并为我需要的变量调用一个属性文件。我试图尽可能具体,这样你们就可以了解到底发生了什么,但问题是我不明白我收到的错误如何影响我正在测试的内容。我会尽力解释清楚

package dataSheet;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Enumeration;
    import java.util.Properties;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.testng.annotations.Parameters;

    import toolsBS.Login;

    public class ReadFileData extends Login {
        WebDriver driver;
        Login objLogin; // Declare a variable of type Login

        public ReadFileData(WebDriver driver) {
            super(driver);
            // TODO Auto-generated constructor stub
        }

        File file = new File(
                "C:\\Users\\andy.williams\\BlueSource\\src\\main\\java\\dataSheet\\dataFile.properties");

        FileInputStream fileInput;
        {
            try {
                fileInput = new FileInputStream(file);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        Properties prop = new Properties();
        {
            // load properties file
            try {
                prop.load(fileInput);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void Setup() {
            String browser = prop.getProperty("dataFile.browser");
            String getURL = prop.getProperty("dataFile.URL");
            String strUsername = prop.getProperty("dataFile.Username");
            String strPassword = prop.getProperty("dataFile.Password");
            if (browser.equalsIgnoreCase("firefox")) { // Compares this String to
                // another String, ignoring case considerations. Two
                // strings are considered equal ignoring case if
                // they are of the same length and corresponding characters in the
                // two strings are equal ignoring case.
                driver = new FirefoxDriver(); // Construct a new object and store a
                // reference to it in the variable.

            }

            else if (browser.equalsIgnoreCase("chrome")) { // Compares this String
                // to another String, ignoring case considerations. Two
                // strings are considered equal ignoring case if they are of the
                // same length and corresponding characters in the two strings are
                // equal ignoring case.
                System.setProperty("webdriver.chrome.driver",
                        "C:\\Users\\andy.williams\\Desktop\\chromedriver.exe"); // Set
                // to
                // specified
                // Browser
                driver = new ChromeDriver(); // Construct a new object and store a
                // reference to it in the variable.
            }

            else if (browser.equalsIgnoreCase("InternetExplorer")) {
                // Compares this String to another String, ignoring case
                // considerations. Two strings are considered equal
                // ignoring case if they are of the same length and
                // corresponding characters in the two strings are equal ignoring
                // case.

                System.setProperty("webdriver.ie.driver",
                        "C:\\Users\\andy.williams\\Desktop\\IEDriverServer.exe"); // Set
                // to
                // specified
                // Browser
                driver = new InternetExplorerDriver(); // Construct a new object and
                // store a reference to it
                // in the variable.

            }
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Set
                                                                                // Specified
                                                                                // Time
                                                                                // Before
                                                                                // Timeout

            driver.get(getURL); // Call desired parameter to initiate the URL
            // Selection
            driver.manage().window().maximize(); // Maximize WebDriver window

            objLogin = new Login(driver); // Construct a new object and store a
            // reference to it in the variable.
            objLogin.loginToBlueSource(strUsername, strPassword); // Calling method
                                                                    // from login
                                                                    // class
                                                                    // assigning
                                                                    // desired
                                                                    // Username and
                                                                    // Password

        }

    }
这是我的数据文件

 # This file is used to store URL,browser and Login Credentials

    browser=chrome
    URL=http://bluesourcestaging.herokuapp.com/login
    Username=adam.thomas
    Password=asdf 
现在我将向您展示我正在呼叫的测试

package calendarPage;

    import org.openqa.selenium.WebDriver;
    import org.testng.Assert;
    import org.testng.Reporter;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.Parameters;
    import org.testng.annotations.Test;

    import toolsBS.Login;
    import calendar.Calendar;
    import dataSheet.ReadFileData;

    public class Practice extends ReadFileData {
        WebDriver driver;
        Login objLogin; // Declare a variable of type Login
        Calendar objCal; // Declare a variable of type Calendar

        public Practice(WebDriver driver) {
            super(driver);
            // TODO Auto-generated constructor stub
        }

        @Test
        // Call the Current Test
        public void Practice() { // Call Method
            Setup(); // Call Setup from ReadFileData Class
            objCal = new Calendar(driver); // Construct a new object and store a
                                            // reference to it in the variable.
            Assert.assertTrue(objCal.CalendarPageLoaded(), // Assert Method
                                                            // called returns value
                                                            // of True, otherwise
                                                            // state the page didn't
                                                            // load
                    "Calendar Page didn't Load");
            Reporter.log("Success, the Calendar Page Loaded<br>"); // Reports
                                                                    // success of
                                                                    // the desired
                                                                    // Test/Method

        }

        // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        @AfterTest
        // The annotated method will be run after all the test methods belonging to
        // the classes inside the <test> tag have run.
        public void closeBrowser() {

            driver.getCurrentUrl();
            driver.quit(); // close browser after each test
        }
    }

您尚未定义无参数构造函数:

public Practice(){
 ...
}

您已经定义了一个名为Practice的public void方法,IDE会给您一个警告。

请编辑您的问题并用代码替换图像,图像不够大,无法读取文本(可能只是我的显示器?)。如果代码很长,那么它将附加滚动条。这已更新。我为混淆道歉。我的道歉我仍然不知道如何处理此问题。我看到我收到了一条错误消息,解释了你说的话,但我认为我已经定义了一个无参数构造函数。我在@Test注释上方定义了一个构造函数,如果要启动测试,则在下面调用了方法,因此我不明白需要编辑什么。您键入了public void Practice(),这是一个返回void的方法。删除void,使其成为构造函数。所以“公共void实践”需要删除void,即使它是一种方法?每次我运行@Test注释时,我都会调用一个方法,为什么现在不同了?反正你需要一个无参数构造函数。如果您想将public void Practice()下的代码作为测试方法保留,请重命名它。
public Practice(){
 ...
}