2016-04-26 122 views
1

這是我的TestNG的類java.lang.ExceptionInInitializerError在運行TestNG的測試用例selenuim

/** 
* 
*/ 
package com.igate.test; 


import org.openqa.selenium.remote.RemoteWebDriver; 
import org.testng.annotations.BeforeClass; 
import org.testng.annotations.Test; 

import com.igate.framework.BaseTestCase; 
import com.igate.framework.ExecutionObject; 
import com.igate.framework.GalenTestLayout; 
import com.igate.framework.Reporter; 
import com.igate.framework.WebDriver; 

@Test 
public class FleetBooking extends BaseTestCase { 

    public FleetBooking() { 
     super(); 
    } 

    public ExecutionObject exeObj; 

    @BeforeClass 
    public void createDoc() throws Exception { 
     Reporter.createDoc(deviceDetail); 
     exeObj = new ExecutionObject(); 
    } 

    public void test_case1() throws Exception { 
     WebDriver oWD = null; 

     if (runType.contains("mobile")) { 
      oWD = new WebDriver(ObjMap, caps, deviceDetail); 
     } else if (runType.contains("desktop")) { 
      oWD = new WebDriver(ObjMap, caps); 
     } 

     try { 

      oWD.startTestCase("test_casen1", exeObj); 
      oWD.launchURL("https://fleet.igate.com/fleet/Login.htm"); 

      oWD.wait("MW"); 
      oWD.setPage("LoginPage"); 
      oWD.enterText("username", "831457"); 
      RemoteWebDriver driver = oWD.getDriver(); 
      System.out.println(" returned driver "+driver); 
      GalenTestLayout layout = new GalenTestLayout(); 
      layout.testLayout(driver, "fleet"); 
      //oWD.layoutTest("fleet"); 
      /*try { 
       System.out.println("layout under process"); 
       LayoutReport layoutReport = Galen.checkLayout(driver, "gspecs/fleet.gspec", 
         Arrays.asList("mobile","desktop")); 
       // Creating a list of tests 
       List<GalenTestInfo> tests = new LinkedList<GalenTestInfo>(); 

       // Creating an object that will contain the information about the 
       // test 
       GalenTestInfo test = GalenTestInfo 
         .fromString("Login page on mobile device test"); 

       // Adding layout report to the test report 
       test.getReport().layout(layoutReport, 
         "check layout on mobile device"); 
       tests.add(test); 



       System.out.println("report created in reports folder"); 
       // Exporting all test reports to html 
       new HtmlReportBuilder().build(tests, 
         "reports"); 

      } catch (IOException e) { 
       System.out.println("error 1"+e.getMessage()); 
       e.printStackTrace(); 
      }*/ 

      oWD.endTestCase(); 
     } catch (Exception e) { 
      System.out.println("SYSOUT - exception : " + e); 
      oWD.endTestCase(); 
     } 

    } 

} 

這裏是我的GalenTestLayout

package com.igate.framework; 

import java.io.IOException; 
import java.util.Arrays; 
import java.util.LinkedList; 
import java.util.List; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.remote.RemoteWebDriver; 
import org.testng.annotations.Test; 

import com.galenframework.api.Galen; 
import com.galenframework.reports.GalenTestInfo; 
import com.galenframework.reports.HtmlReportBuilder; 
import com.galenframework.reports.model.LayoutReport; 
import com.galenframework.testng.GalenTestNgTestBase; 

public class GalenTestLayout { 

    public RemoteWebDriver driver; 

    @Test 
    public void testLayout(RemoteWebDriver driver,String gspec) { 

     System.out.println("driver in layout method "+driver); 


     LayoutReport layoutReport; 
     try { 
      System.out.println("layout under process"); 
      layoutReport = Galen.checkLayout(driver, "gspecs/fleet.gspec", 
        Arrays.asList("mobile","desktop")); 
      // Creating a list of tests 
      List<GalenTestInfo> tests = new LinkedList<GalenTestInfo>(); 

      // Creating an object that will contain the information about the 
      // test 
      GalenTestInfo test = GalenTestInfo 
        .fromString("Login page on mobile device test"); 

      // Adding layout report to the test report 
      test.getReport().layout(layoutReport, 
        "check layout on mobile device"); 
      tests.add(test); 

      System.out.println("report created in reports folder"); 
      // Exporting all test reports to html 
      new HtmlReportBuilder().build(tests, 
        "reports"); 

     } catch (IOException e) { 
      System.out.println("error in layout method "+e.getMessage()); 
      e.printStackTrace(); 
     } 

    } 

} 

我收到錯誤我FleetBooking類在

**GalenTestLayout layout = new GalenTestLayout(); 
      layout.testLayout(driver, "fleet");** 

這些是我的錯誤日誌

[TestNG] Running: 
    C:\Users\pmadge\AppData\Local\Temp\testng-eclipse-1054887367\testng-customsuite.xml 

bin compiled version 1.1 
2016-04-26 20:14:08 INFO BaseTestCase:134 - Framework assigned in Internal Path : - Successfull 
device size :3 
*************taken device*********** 0 
increasing count :1 
looped i :0 
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 20891 
Only local connections are allowed. 
2016-04-26 20:14:10 INFO WebDriver:739 - StartTestCase - test_casen1 - Successfull 
2016-04-26 20:14:10 INFO WebDriver:181 - Launch URL - : https://fleet.igate.com/fleet/Login.htm - Successfull 
########$$$$$$$$$$%%%%%%%%%%%%%% ::::::::::::: null 
2016-04-26 20:14:15 INFO WebDriver:155 - SetPage - : LoginPage - Successfull 
2016-04-26 20:14:17 INFO WebDriver:610 - GetControl - Action Performed : username - Successfull 
2016-04-26 20:14:17 INFO WebDriver:622 - FetchControl - Action Performed - Successfull 
2016-04-26 20:14:19 INFO WebDriver:612 - GetControl - WebElement - Successfull 
2016-04-26 20:14:19 INFO WebDriver:206 - enterText - in: username value: 831457 - Successfull 
returned driver ChromeDriver: chrome on XP (92edabdf1bacb26c65c50ac893f7da3f) 
driver in layout method ChromeDriver: chrome on XP (92edabdf1bacb26c65c50ac893f7da3f) 
layout under process 
FAILED: test_case1 
java.lang.ExceptionInInitializerError 
    at com.galenframework.rainbow4j.Rainbow4J.loadImage(Rainbow4J.java:286) 
    at com.galenframework.utils.GalenUtils.takeScreenshot(GalenUtils.java:314) 
    at com.galenframework.browser.SeleniumBrowser.makeSimpleScreenshot(SeleniumBrowser.java:97) 
    at com.galenframework.browser.SeleniumBrowser.createScreenshot(SeleniumBrowser.java:90) 
    at com.galenframework.page.selenium.SeleniumPage.createScreenshot(SeleniumPage.java:161) 
    at com.galenframework.api.Galen.checkLayoutForPage(Galen.java:100) 
    at com.galenframework.api.Galen.checkLayout(Galen.java:86) 
    at com.galenframework.api.Galen.checkLayout(Galen.java:69) 
    at com.galenframework.api.Galen.checkLayout(Galen.java:59) 
    at com.galenframework.api.Galen.checkLayout(Galen.java:154) 
    at com.galenframework.api.Galen.checkLayout(Galen.java:128) 
    at com.igate.framework.GalenTestLayout.testLayout(GalenTestLayout.java:31) 
    at com.igate.test.FleetBooking.test_case1(FleetBooking.java:63) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) 
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) 
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) 
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) 
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) 
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) 
    at org.testng.TestRunner.privateRun(TestRunner.java:767) 
    at org.testng.TestRunner.run(TestRunner.java:617) 
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) 
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) 
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) 
    at org.testng.SuiteRunner.run(SuiteRunner.java:240) 
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) 
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) 
    at org.testng.TestNG.run(TestNG.java:1057) 
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) 
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) 
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) 
Caused by: java.lang.SecurityException: sealing violation: can't seal package com.sun.media.imageioimpl.plugins.jpeg2000: already loaded 
    at java.net.URLClassLoader.getAndVerifyPackage(Unknown Source) 
    at java.net.URLClassLoader.definePackageInternal(Unknown Source) 
    at java.net.URLClassLoader.defineClass(Unknown Source) 
    at java.net.URLClassLoader.access$100(Unknown Source) 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at java.util.ServiceLoader$LazyIterator.nextService(Unknown Source) 
    at java.util.ServiceLoader$LazyIterator.next(Unknown Source) 
    at java.util.ServiceLoader$1.next(Unknown Source) 
    at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(Unknown Source) 
    at javax.imageio.spi.IIORegistry.<init>(Unknown Source) 
    at javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown Source) 
    at javax.imageio.ImageIO.<clinit>(Unknown Source) 
    ... 37 more 


=============================================== 
    Default test 
    Tests run: 1, Failures: 1, Skips: 0 
=============================================== 


=============================================== 
Default suite 
Total tests run: 1, Failures: 1, Skips: 0 
=============================================== 

[TestNG] Time taken by [email protected]: 21 ms 
[TestNG] Time taken by [email protected]: 76 ms 
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms 
[TestNG] Time taken by [email protected]: 36 ms 
[TestNG] Time taken by org.testng.reporters.XM[email protected]: 4 ms 
[TestNG] Time taken by [email protected]: 3 ms 

我的鉻驅動程序已正確初始化,因爲您可以在我的輸出日誌中看到。

當我運行功能layout.testLayout(driver,「fleet」);作爲一個獨立的類運行,但是當我從testng類調用這個方法時,我得到了異常。我嘗試過很多辦法,但它仍然是給我的錯誤

回答

3

的錯誤是:

Caused by: java.lang.SecurityException: sealing violation: can't seal package com.sun.media.imageioimpl.plugins.jpeg2000: already loaded 
    at java.net.URLClassLoader.getAndVerifyPackage(Unknown Source) 

因此,這意味着你儘量密封已經加載包。該軟件包位於jai_imageio - *。jar文件中。檢查你是否有兩個類似的罐子,並刪除其中的一個。

+0

找你的項目是有一些設置問題,請參閱http:/ /stackoverflow.com/questions/10093176/java-lang-securityexception-sealing-violation – hypery2k

+0

謝謝alpert,不知道我的配置你能夠知道問題的根本原因。刪除那個jar解決了我的問題。非常感謝 ! –