Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package com.nativeapp.runner;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.apache.log4j.Logger;
  7.  
  8. import com.clioption.CliParser;
  9. import com.clioption.SuiteInvocationCountOption;
  10. import com.clioption.TestNgGroupOption;
  11. import com.clioption.TestNgSuiteOption;
  12. import com.clioption.TestNgSuiteThreadCountOption;
  13. import com.clioption.TestNgThreadCountOption;
  14. import com.nativeapp.mobiledriver.device.Device;
  15. import com.nativeapp.mobiledriver.device.DeviceStorage;
  16. import com.nativeapp.runner.clioption.AppiumServerOption;
  17. import com.nativeapp.runner.clioption.DeviceNameOption;
  18. import com.nativeapp.runner.clioption.DriverTypeOption;
  19. import com.nativeapp.runner.clioption.MRSSOption;
  20. import com.nativeapp.runner.clioption.OSNameOption;
  21. import com.nativeapp.runner.clioption.ProxyPortOption;
  22. import com.nativeapp.runner.clioption.RerunTestOption;
  23. import com.nativeapp.runner.clioption.UdidOption;
  24. import com.runner.Runner;
  25.  
  26. public class TestRunner extends Runner {
  27.  
  28.     private static final Logger LOGGER = Logger.getLogger(TestRunner.class);
  29.  
  30.     public TestRunner(String[] args) {
  31.         super(args);
  32.     }
  33.  
  34.     public static void main(String[] args) {
  35.         Runner tr;
  36.         try {
  37.             tr = new TestRunner(args);
  38.  
  39.             Runtime.getRuntime().addShutdownHook(new ClearShutdownHook());
  40.  
  41.             @SuppressWarnings("rawtypes")
  42.             List<Class> listeners = new ArrayList<Class>();
  43.  
  44.             if (DeviceConfig.isRerunTests()) {
  45.                 listeners.add(RerunTestListener.class);
  46.             }
  47.             listeners.add(CustomXMLReporter.class);
  48.             listeners.add(CustomHTMLReporter.class);
  49.             listeners.add(SuiteListener.class);
  50.  
  51.             tr.setListeners(listeners);
  52.  
  53.             // ScreenshotUtils.setScreenshotDir("test-output");
  54.             tr.run();
  55.         } catch (Exception e) {
  56.             LOGGER.fatal(e.getMessage(), e);
  57.             // throw new RuntimeException(e);
  58.         }
  59.  
  60.         finally {
  61.             RerunTestListener.rerunFailedTests(args);
  62.             int exitCode = BuildResult.getExitResult();
  63.             LOGGER.info("Exit with code : " + exitCode);
  64.             System.exit(exitCode);
  65.         }
  66.     }
  67.  
  68.     public static class ClearShutdownHook extends Thread {
  69.  
  70.         private static final Logger LOGGER = Logger.getLogger(TestRunner.class);
  71.  
  72.         @Override
  73.         public void run() {
  74.             LOGGER.info("Running shutdown hook kill appium-server, shutdown proxy servers...");
  75.  
  76.             for (Device device : DeviceStorage.getDevices()) {
  77.                 try {
  78.                     // TODO for iOS
  79.                     // MacExecutor.switchSystemProxy(SystemProxyState.OFF,
  80.                     // device
  81.                     // .getAppiumServer(), device.getProxyType().getPort());
  82.  
  83.                     device.getAppiumProcess().killMe();
  84.                    
  85.                 } catch (Exception e) {
  86.                     LOGGER.info("Exception while killing appium servers: "
  87.                             + e.getMessage());
  88.                 }
  89.             }
  90.             for (Device device : DeviceStorage.getDevices()) {
  91.                 device.getProxyRunner().stopMe();
  92.             }
  93.  
  94.         }
  95.     }
  96.  
  97.     public void addCommandLineOptions() {
  98.         CliParser.getCmdLineOptions().add(new TestNgSuiteOption());
  99.         CliParser.getCmdLineOptions().add(new TestNgGroupOption());
  100.         CliParser.getCmdLineOptions().add(new TestNgThreadCountOption());
  101.         CliParser.getCmdLineOptions().add(new SuiteInvocationCountOption());
  102.         CliParser.getCmdLineOptions().add(new RerunTestOption());
  103.         CliParser.getCmdLineOptions().add(new DeviceNameOption());
  104.         CliParser.getCmdLineOptions().add(new UdidOption());
  105.         CliParser.getCmdLineOptions().add(new ProxyPortOption());
  106.         CliParser.getCmdLineOptions().add(new OSNameOption());
  107.         CliParser.getCmdLineOptions().add(new AppiumServerOption());
  108.         CliParser.getCmdLineOptions().add(new DriverTypeOption());
  109.         CliParser.getCmdLineOptions().add(new MRSSOption());
  110.         CliParser.getCmdLineOptions().add(new TestNgSuiteThreadCountOption());
  111.     }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement