Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当通过TestNG selenium automation打开另一个页面时,java.lang.ExceptionInInitializeError_Java_Selenium_Exception_Pom.xml_Ui Automation - Fatal编程技术网

当通过TestNG selenium automation打开另一个页面时,java.lang.ExceptionInInitializeError

当通过TestNG selenium automation打开另一个页面时,java.lang.ExceptionInInitializeError,java,selenium,exception,pom.xml,ui-automation,Java,Selenium,Exception,Pom.xml,Ui Automation,我使用了两页的POM模型。登录页面和主页。这两个页面有两个测试类(LoginTest和HomeTest)以及BaseTest(驱动程序初始化目的&由所有4个类继承)。当点击loginpage.verifyLogin(email_id,pswrd)时,主页应该被打开。我在执行登录测试用例时得到java.lang.ExceptionInInitializerError PS。如果将verifyLogin()的返回类型更改为void,则工作正常。 请参阅基本测试 public class BaseTe

我使用了两页的POM模型。登录页面和主页。这两个页面有两个测试类(LoginTest和HomeTest)以及BaseTest(驱动程序初始化目的&由所有4个类继承)。当点击loginpage.verifyLogin(email_id,pswrd)时,主页应该被打开。我在执行登录测试用例时得到java.lang.ExceptionInInitializerError

PS。如果将verifyLogin()的返回类型更改为void,则工作正常。

请参阅基本测试

public class BaseTest 
{
    public static WebDriver driver ;
    public static String chrome_path ="/home/downloads/chromedriver";
   public static String property_file_path ="/home/CompleteMotorJourneyAutoTest/src/test/java/com/qa/utils/loginDetails.properties";
    
    public BaseTest()
    {
        try {
            FileInputStream fis = new FileInputStream(property_file_path);
            Properties prop = new Properties();
            prop.load(fis);         
            }catch(Exception e) {System.out.println("Exception occured during reading the property file !");}
    }
    
    public static void initialization() 
    {           System.setProperty("webdriver.chrome.driver",chrome_path);
                driver=new ChromeDriver();          
        driver.get(prop.getProperty("URL"));
    }
}
登录页

public class LoginPage extends BaseTest
{
    @FindBy(xpath="//*[@id=\"loginform\"]/div[1]/div[2]/input")
    WebElement email_id_field;
    @FindBy(xpath="//*[@id=\"loginform\"]/div[2]/div[2]/input")
    WebElement password_field;
    @FindBy(xpath="//*[@id='loginform']/input")
    WebElement login_button_Field;

    public LoginPage()
    {       PageFactory.initElements(driver, this);     }

    public HomePage verifyLogin(String username,String password) 
    {   email_id_field.sendKeys(username);
        password_field.sendKeys(password);
        login_button_Field.click();
        return new HomePage();
    }
}
逻辑测试

public class LoginTest extends BaseTest 
{   LoginPage loginpage;
    HomePage homepage;  

    public LoginTest() 
    {   super();    }

    //Browser initialization/Environment setup  <----------------------
    @BeforeMethod                               
    public void setup() 
    {   initialization();
        loginpage = new LoginPage();    }

    //login with correct credentials            <----------------------
    @Test(priority=0)
    public void loginWithCorrectCredentials() 
    {       homepage=loginpage.verifyLogin(prop.getProperty("login_id"),prop.getProperty("login_password")); 
    }
    
    //Browser closure                           <----------------------
    @AfterMethod
    public void tearDown()
    {   driver.quit();      }
}

公共类LoginTest扩展了BaseTest
{LoginPage LoginPage;
主页;
公共登录测试()
{super();}

//浏览器初始化/环境设置已关闭。问题是HomePage.java类具有HomeTest.java类的XPath和方法。HomePage.java类具有静态WebElements,其中XPath不正确。现在,更正XPath并发现其工作正常

[RemoteTestNG] detected TestNG version 7.0.1
Starting ChromeDriver 86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378}) on port 8944
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Oct 28, 2020 3:55:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
FAILED CONFIGURATION: @BeforeMethod setup
java.lang.ExceptionInInitializerError
    at com.qa.testpages.LoginPage.verifyLogin(LoginPage.java:115)
    at com.qa.testcase.HomeTest.setup(HomeTest.java:35)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)
    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:63)
    at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:348)
    at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:302)
    at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:695)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:523)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
    at org.testng.TestRunner.privateRun(TestRunner.java:766)
    at org.testng.TestRunner.run(TestRunner.java:587)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
    at org.testng.SuiteRunner.run(SuiteRunner.java:286)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1109)
    at org.testng.TestNG.runSuites(TestNG.java:1039)
    at org.testng.TestNG.run(TestNG.java:1007)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.NullPointerException
    at com.qa.testpages.HomePage.<clinit>(HomePage.java:32)
    ... 34 more

SKIPPED CONFIGURATION: @AfterMethod tearDown