无法实例化类-Selenium WebDriver(TestNG)

时间:2018-09-05 17:15:00

标签: java selenium-webdriver testng

在使用Java在Selenium网络驱动程序中运行我的一个测试用例时,我面临着“无法实例化类”错误。

下面是测试功能的类别

public class LoginPageTest extends TestBase{

    LoginPage loginPage;
    HomePage homepage;

    public LoginPageTest(){

        super();
    }

    @BeforeMethod
    public void setUp(){

        initialization();
        loginPage = new LoginPage();

    }

    @Test(priority=1)
    public void loginPageTitleTest(){

        String title = loginPage.validateLoginPageTitle();
        Assert.assertEquals(title,"#1 Free CRM software in the cloud for sales and service");

    }

    @Test(priority=2)
    public void crmLogoImageTest(){

        boolean flag = loginPage.validateCRMImage();

        Assert.assertTrue(flag,"Image not found");
    }

    @Test(priority=3)
    public void loginTest(){

        homepage = loginPage.login(prop.getProperty("username"), prop.getProperty("password"));
    }


    @AfterMethod
    public void tearDown(){

        driver.quit();
    }

}

================================================ ========================

Test Base Class:

package com.crm.qa.base;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
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;

import com.crm.qa.util.TestUtil;

public class TestBase {

    public static WebDriver driver;
    public static Properties prop;

    public TestBase() {

        prop = null;
        try {
            FileInputStream ip = new FileInputStream("E:\\Nitin_Workspace\\FreeCRMTest\\src\\main\\java\\com\\crm\\qa\\config\\config.properties");

            prop.load(ip);

        } catch (FileNotFoundException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }   

    }

    public static void initialization(){

        String browserName = prop.getProperty("browser");
        String chromePath = prop.getProperty("chromePath");
        String FFPath = prop.getProperty("FFPath");

        if(browserName.equals("chrome")){

            System.setProperty("webdriver.chrome.driver", chromePath);
            driver = new ChromeDriver();
        }else if(browserName.equals("FireFox")){

            System.setProperty("webdriver.chrome.driver", FFPath);
            driver = new FirefoxDriver();
        }

        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);

        driver.get(prop.getProperty("url"));

    }


}

================================================ =============================

[RemoteTestNG] detected TestNG version 6.13.1
org.testng.TestNGException: 
Cannot instantiate class com.crm.qa.testcases.LoginPageTest
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:30)
    at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:423)
    at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:336)
    at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
    at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190)
    at org.testng.TestClass.getInstances(TestClass.java:95)
    at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:81)
    at org.testng.TestClass.init(TestClass.java:73)
    at org.testng.TestClass.<init>(TestClass.java:38)
    at org.testng.TestRunner.initMethods(TestRunner.java:389)
    at org.testng.TestRunner.init(TestRunner.java:271)
    at org.testng.TestRunner.init(TestRunner.java:241)
    at org.testng.TestRunner.<init>(TestRunner.java:192)
    at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33)
    at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66)
    at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:713)
    at org.testng.SuiteRunner.init(SuiteRunner.java:260)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:198)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1271)

0 个答案:

没有答案