public static void premain ( String agentArgs , Instrumentation inst ) throws YamlConvertException , IllegalTestScriptException , IOException , ClassNotFoundException , InstantiationException , IllegalAccessException { String configFilePath ; String propValue = System . getProperty ( "sahagin.configPath" ) ; if ( ! StringUtils . isBlank ( propValue ) ) { configFilePath = propValue ; } else if ( agentArgs != null ) { // check agent argument for backward compatibility configFilePath = agentArgs ; } else { configFilePath = "sahagin.yml" ; } JavaConfig config = JavaConfig . generateFromYamlConfig ( new File ( configFilePath ) ) ; Logging . setLoggerEnabled ( config . isOutputLog ( ) ) ; AcceptableLocales locales = AcceptableLocales . getInstance ( config . getUserLocale ( ) ) ; JavaAdapterContainer . globalInitialize ( locales , config . getTestFramework ( ) ) ; SysMessages . globalInitialize ( locales ) ; // default adapters new JavaSystemAdapter ( ) . initialSetAdapter ( ) ; new JUnit3Adapter ( ) . initialSetAdapter ( ) ; new JUnit4Adapter ( ) . initialSetAdapter ( ) ; new TestNGAdapter ( ) . initialSetAdapter ( ) ; new JavaLibAdapter ( ) . initialSetAdapter ( ) ; new WebDriverAdapter ( ) . initialSetAdapter ( ) ; new AppiumAdapter ( ) . initialSetAdapter ( ) ; new SelendroidAdapter ( ) . initialSetAdapter ( ) ; new IOSDriverAdapter ( ) . initialSetAdapter ( ) ; new FluentLeniumAdapter ( ) . initialSetAdapter ( ) ; for ( String adapterClassName : config . getAdapterClassNames ( ) ) { // TODO handle exception thrown by forName or newInstance method // more appropriately Class < ? > adapterClass = Class . forName ( adapterClassName ) ; assert adapterClass != null ; Object adapterObj = adapterClass . newInstance ( ) ; assert adapterObj != null ; assert adapterObj instanceof Adapter ; Adapter adapter = ( Adapter ) adapterObj ; adapter . initialSetAdapter ( ) ; } if ( ! JavaAdapterContainer . globalInstance ( ) . isRootMethodAdapterSet ( ) ) { throw new RuntimeException ( String . format ( MSG_TEST_FRAMEWORK_NOT_FOUND , config . getTestFramework ( ) ) ) ; } // delete previous data if ( config . getRootBaseRunOutputIntermediateDataDir ( ) . exists ( ) ) { FileUtils . deleteDirectory ( config . getRootBaseRunOutputIntermediateDataDir ( ) ) ; } SrcTree srcTree = generateAndDumpSrcTree ( config , locales ) ; RunResultsGenerateHookSetter transformer = new RunResultsGenerateHookSetter ( configFilePath , srcTree ) ; inst . addTransformer ( transformer ) ; }
agentArgs is configuration YAML file path