{"size": 2146, "ext": "js", "max_stars_repo_path": "src/index.js", "max_stars_repo_name": "SkyWalker1005/testcafe-browser-provider-portable", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/index.js", "max_issues_repo_name": "SkyWalker1005/testcafe-browser-provider-portable", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/index.js", "max_forks_repo_name": "SkyWalker1005/testcafe-browser-provider-portable", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.6133333333, "max_line_length": 121, "alphanum_fraction": 0.6202236719}
/* eslint-disable */
import path from 'path';
import browserTools from 'testcafe-browser-tools';

function getScreenSize () {
    return { width: screen.availWidth, height: screen.availHeight };
}

export default {
    // Multiple browsers support
    isMultiBrowser: true,
    screenSizes: {},

    // Required - must be implemented
    // Browser control
    async openBrowser (id, pageUrl, browserName) {
        var browserInfo = {};

        switch (browserName) {
            case 'firefox':
                browserInfo.path = path.join(process.env.PORTABLE_BROWSERS_PATH, 'Mozilla Firefox/firefox.exe');
                browserInfo.cmd  = '-new-window';
                break;
            case 'chrome':
                browserInfo.path = path.join(process.env.PORTABLE_BROWSERS_PATH, 'Google/Chrome/Application/chrome.exe');
                browserInfo.cmd  = '--new-window';
                break;
            default:
                throw new Error('Unsupported browser!');
        }

        await browserTools.open(browserInfo, pageUrl);

        await this.waitForConnectionReady(id);

        this.screenSizes[id] = await this.runInitScript(id, getScreenSize.toString());
    },

    async closeBrowser (id) {
        await browserTools.close(id);
    },

    
    // Browser names handling
    async getBrowserList () {
        return ['firefox', 'chrome'];
    },

    async isValidBrowserName (browserName) {
        var browserList = await this.getBrowserList();

        return browserList.indexOf(browserName) > -1;
    },
    

    // Extra methods
    async resizeWindow (id, width, height, currentWidth, currentHeight) {
        await browserTools.resize(id, currentWidth, currentHeight, width, height);
    },

    async canResizeWindowToDimensions (id, width, height) {
        var { width: screenWidth, height: screenHeight } = this.screenSizes[id];

        return width <= screenWidth && height <= screenHeight;
    },

    async maximizeWindow (id) {
        await browserTools.maximize(id);
    },

    async takeScreenshot (id, screenshotPath) {
        await browserTools.screenshot(id, screenshotPath);
    }
};
