WebDriver Ruby Custom FirefoxProfile

时间:2016-11-07 06:48:37

标签: ruby selenium firefox

我有一个我希望启动测试的Firefox个人资料。它目前是我的测试机器的Firefox副本中唯一加载的配置文件。当我加载WebDriver Remote时,它没有加载我的个人资料。首先我尝试了这个:

profile = File.read '/home/me/firefoxprofile.zip.b64'
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities)

这没有用,并打开了一个空白配置文件的浏览器。然后我记得在PHP WebDriver中有一个要求复制配置文件和Base64编码它。所以我这样做了:

<!DOCTYPE html>
<html>

<head>
    <title>Video Solution</title>
    <link href="https://vjs.zencdn.net/5.11.9/video-js.min.css" rel="stylesheet">
    <script src="https://vjs.zencdn.net/5.11.9/video.min.js"></script>
</head>
<body>
    <script src="js/vast-client.js"></script>
    <h1>Video below	</h1>

    VAST:
    <textarea id="vast_tag" style="width: 100%;"> </textarea>
    <button id="refresh_tag">Load Vast</button>
    <div id="player_container"></div>
    <script>
        function getParameterByName(name, url) {
            if (!url) {
                url = window.location.href;
            }
            name = name.replace(/[\[\]]/g, "\\$&");
            var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
        }
        URL = "https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=";
        //URL = "http://a.teads.tv/vast/get/70533";
        document.getElementById("vast_tag").value = URL;

        load_ad = function () {
            var container = document.getElementById("player_container");
            var URL = document.getElementById("vast_tag").value;
            console.log("URL::", URL);

            DMVAST.client.get(URL, (function (vast) {
                if (!vast) {
                    console.log("Not able to load VAST tag");
                    container.innerHTML = "Not able to load VAST tag";
                    return;
                }
                console.log("VAST", vast);

                var mediafiles = (function () {
                    var media = [];
                    for (var adid = 0; adid < vast.ads.length; adid++) {
                        var ad = vast.ads[adid];
                        for (var creativeid = 0; creativeid < ad.creatives.length; creativeid++) {
                            var creative = ad.creatives[creativeid];
                            if (!creative.mediaFiles) continue;
                            for (var mediaid = 0; mediaid < creative.mediaFiles.length; mediaid++) {
                                var mediafile = creative.mediaFiles[mediaid]
                                if (mediafile.mimeType == "application/javascript") {
                                    continue;
                                }
                                media.push(mediafile);
                                console.log(mediafile);
                            }
                        }
                    }
                    return media;
                })();

                var media_url = "http://techslides.com/demos/sample-videos/small.mp4";
                var media_type = "video/mp4";
                var width = 640;
                var height = 480;
                var playerhtml = "";
                var source = "";

                console.log("mediafiles", mediafiles);

                for (var sourceid = 0; sourceid < mediafiles.length; sourceid++) {
                    if (mediafiles[sourceid].mimeType == "video/x-flv") {
                        media_url = mediafiles[sourceid].fileURL;
                        media_type = mediafiles[sourceid].mimeType;
                        source += "<source src=\"" + media_url + "\" type=\"" + media_type + "\" />\n";
                    }
                }
                console.log("source", source);
                //if(source.type ==)

                playerhtml += "<video autoplay preload=\"auto\" class=\"dw_player_video\" class=\"video-js vjs-default-skin\"\n width=\"640\" height=\"480\"\n  poster=\"http://video-js.zencoder.com/oceans-clip.png\"\n  data-setup='{\"techOrder\": [\"html5\", \"flash\"] }'>\n" + source + "<p class=\"vjs-no-js\">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href=\"http://videojs.com/html5-video-support/\" target=\"_blank\">supports HTML5 video</a></p>\n</video>";
                container.innerHTML = playerhtml;

                var player_elements = document.getElementsByClassName("dw_player_video");
                for (var pid = 0; pid < player_elements.length; pid++) {
                    (function () {
                        var player = videojs(player_elements[pid], {}, function () {
                            // Player (this) is initialized and ready.
                            console.log("PLAYER READY")
                            // player.controlBar.hide();
                        });
                    })();
                }
            }));
        }
        document.getElementById("refresh_tag").addEventListener("click", function () {
            load_ad();
        })
    </script>
</body>
</html>

但我仍然坚持使用空白的个人资料。 :(

我在个人资料中设置了很多自定义偏好设置和扩展程序,并希望为每个测试加载它。

更新

我还尝试使用webdriver.jar添加-FirefoxProfilePath,但也无法加载我的个人资料。

如何在WebDriver Remote中加载自定义Firefox配置文件进行测试?

0 个答案:

没有答案