Search in sources :

Example 1 with OSUtility

use of com.seleniumtests.util.osutility.OSUtility in project seleniumRobot by bhecquet.

the class BrowserInfo method getProgramPid.

/**
 * get
 * @return
 */
public List<Long> getProgramPid(String programName, List<Long> existingPids) {
    final String jvmName = ManagementFactory.getRuntimeMXBean().getName();
    final int index = jvmName.indexOf('@');
    OSUtility osUtility = OSUtilityFactory.getInstance();
    if (index == 0) {
        return new ArrayList<>();
    }
    try {
        String processId = Long.toString(Long.parseLong(jvmName.substring(0, index)));
        return osUtility.getChildProcessPid(Long.parseLong(processId), programName + osUtility.getProgramExtension(), existingPids);
    } catch (Exception e) {
        logger.warn("could not get driver pid", e);
        return new ArrayList<>();
    }
}
Also used : OSUtility(com.seleniumtests.util.osutility.OSUtility) ArrayList(java.util.ArrayList) Win32Exception(com.sun.jna.platform.win32.Win32Exception) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) IOException(java.io.IOException)

Example 2 with OSUtility

use of com.seleniumtests.util.osutility.OSUtility in project seleniumRobot by bhecquet.

the class BrowserInfo method getAllBrowserSubprocessPids.

/**
 * Get the list of pids for the browser launched by driver and all subprocess created by browser
 * @param driverPid
 * @return
 */
public List<Long> getAllBrowserSubprocessPids(List<Long> driverPids) {
    OSUtility osUtility = OSUtilityFactory.getInstance();
    List<Long> allPids = new ArrayList<>(driverPids);
    try {
        for (Long driverPid : driverPids) {
            List<Long> browserPids = osUtility.getChildProcessPid(driverPid, null, new ArrayList<>());
            allPids.addAll(browserPids);
            for (Long browserPid : browserPids) {
                List<Long> subBrowserPids = osUtility.getChildProcessPid(browserPid, null, new ArrayList<>());
                allPids.addAll(subBrowserPids);
            }
        }
        return allPids;
    } catch (IOException e) {
        return new ArrayList<>();
    }
}
Also used : OSUtility(com.seleniumtests.util.osutility.OSUtility) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

OSUtility (com.seleniumtests.util.osutility.OSUtility)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 Win32Exception (com.sun.jna.platform.win32.Win32Exception)1