Example #1
0
        public void TestComscoreHomepage_Fires_Beacon()
        {
            Slimer = new Slimer("http://www.comscore.com/", 1024, 768);
            var resources = Slimer.GetNetworkResources();
            var item      = resources.Select(u => u.StartsWith("http://b.scorecardresearch.com/b?")).Count();

            Assert.GreaterThan(item, 0);
        }
Example #2
0
        public void GetNetworkResources_Returns_InitialGETRequestURL()
        {
            Slimer = new Slimer("http://jimchely.com/", 1024, 768);
            var resources = Slimer.GetNetworkResources();
            var item      = resources.Contains("http://jimchely.com/");

            Assert.IsTrue(item);
        }
Example #3
0
        public void KitchenSink(string url, int w = 1024, int h = 768, int d = 0)
        {
            var dim   = new Point(w, h);
            var delay = d;

            url = HttpUtility.UrlDecode(url);

            using (var slimer = new Slimer(url, dim.X, dim.Y, delay)) {
                var pageDims = slimer.GetPageDimensions();

                Response.Write(
                    Json(new {
                    url       = url,
                    pagedims  = new { width = pageDims.X, height = pageDims.Y },
                    source    = slimer.GetHtml(),
                    resources = slimer.GetNetworkResources()
                }, JsonRequestBehavior.AllowGet)
                    );
            }
        }
Example #4
0
        public void KitchenSink(string url, int w = 1024, int h = 768, int d = 0)
        {
            var dim = new Point(w, h);
            var delay = d;

            url = HttpUtility.UrlDecode(url);

            using (var slimer = new Slimer(url, dim.X, dim.Y, delay)) {
                var pageDims = slimer.GetPageDimensions();

                Response.Write(
                    Json(new {
                                 url = url,
                                 pagedims = new {width = pageDims.X, height = pageDims.Y},
                                 source = slimer.GetHtml(),
                                 resources = slimer.GetNetworkResources()
                             }, JsonRequestBehavior.AllowGet)
                    );
            }
        }
Example #5
0
        public static void Main(string[] args)
        {
            string url;
            bool getSource = false;
            bool getRender = false;
            bool getFullRender = false;
            bool getPageDims = false;
            bool getNetworkResources = false;
            bool runJavascript = false;
            string javascript = "";
            bool help = false;
            int delay = 0;
            var dim = new Point(1024, 768);

            var p = new OptionSet() {
                                        {"source", v => { getSource = true; }},
                                        {
                                            "render", v => {
                                                          getRender = true;
                                                          getFullRender = false;
                                                      }
                                            },
                                        {
                                            "fullrender", v => {
                                                              getRender = true;
                                                              getFullRender = true;
                                                          }
                                            },
                                        {"pagedims", v => { getPageDims = true; }},
                                        {
                                            "dims=", v => {
                                                        var d = v.Split('x');
                                                        if (d.Length != 2) return;
                                                        dim.X = Convert.ToInt32(d[0]);
                                                        dim.Y = Convert.ToInt32(d[1]);
                                                    }
                                            },
                                        {
                                            "js=", v => {
                                                      runJavascript = true;
                                                      javascript = v;
                                                  }
                                            },
                                        {"network", v => { getNetworkResources = true; }},
                                        {"delay=", v => { delay = Convert.ToInt32(v.Trim()); }},
                                        {"h|?|help", v => help = v != null},
                                    };
            var extra = p.Parse(args);

            if (extra.Count > 0) {
                url = string.Join(" ", extra.ToArray());
            }
            else {
                ShowHelp(p);
                return;
            }

            var slimer = new Slimer(url, dim.X, dim.Y, delay);

            if (getSource) {
                Console.WriteLine(slimer.GetHtml());
            }

            if (getPageDims) {
                var d = slimer.GetPageDimensions();
                Console.WriteLine(d.X + " x " + d.Y);
            }

            if (runJavascript) {
                var response = slimer.JavascriptRunner(javascript);
                Console.WriteLine("Javascript response:");
                Console.WriteLine(response);
            }

            if (getRender) {
                var render = slimer.GetRender(getFullRender);
                render.Save("result.jpg", ImageFormat.Jpeg);
                Console.WriteLine("Render complete...Loading it for you.");
                Process.Start("result.jpg");
            }

            if (getNetworkResources) {
                var resources = slimer.GetNetworkResources();
                foreach (var item in resources) {
                    Console.WriteLine(item);
                }
            }

            slimer.Dispose();
        }