public void TestGetJson()
        {
            search = new GoogleSearch(ht, apiKey);
            JObject data        = search.GetJson();
            JArray  coffeeShops = (JArray)data["local_results"]["places"];
            int     counter     = 0;

            foreach (JObject coffeeShop in coffeeShops)
            {
                Assert.IsNotNull(coffeeShop["title"]);
                counter++;
            }
            Assert.IsTrue(counter >= 1);

            coffeeShops = (JArray)data["organic_results"];
            Assert.IsNotNull(coffeeShops);
            foreach (JObject coffeeShop in coffeeShops)
            {
                Console.WriteLine("Found: " + coffeeShop["title"]);
                Assert.IsNotNull(coffeeShop["title"]);
            }

            // Release socket connection
            search.Close();
        }
Beispiel #2
0
        public void HtmlEdit_SetText_Succeeds()
        {
            GoogleHomePage pgGHomePage = WebPage.Launch <GoogleHomePage>("http://www.google.com");

            pgGHomePage.txtSearch.SetText("Coded UI Test Framework");
            GoogleSearch            pgSearch = WebPage.GetPage <GoogleSearch>();
            UITestControlCollection col      = pgSearch.divSearchResults.UnWrap().GetChildren();

            //do something with collection
            pgSearch.Close();
        }
        public void TestGetHtml()
        {
            search = new GoogleSearch(ht, apiKey);
            string htmlContent = search.GetHtml();

            Assert.IsNotNull(htmlContent);
            //Console.WriteLine(htmlContent);
            Assert.IsTrue(htmlContent.Contains("</body>"));
            // Release socket connection
            search.Close();
        }
Beispiel #4
0
        public void HtmlEdit_SetText_Succeeds()
        {
            GoogleHomePage pgGHomePage = BrowserWindowUnderTest.Launch <GoogleHomePage>("http://www.google.com");

            pgGHomePage.txtSearch.Text = "Coded UI Test Framework";
            GoogleSearch pgSearch = BrowserWindowUnderTest.GetBrowserWindow <GoogleSearch>();
// ReSharper disable once UnusedVariable
            UITestControlCollection col = pgSearch.divSearchResults.SourceControl.GetChildren();

            //do something with collection
            pgSearch.Close();
        }
Beispiel #5
0
        public void HtmlEdit_Wrap_Succeeds()
        {
            GoogleHomePage pgGHomePage = WebPage.Launch <GoogleHomePage>("http://www.google.com");

            var tmp = new HtmlEdit(pgGHomePage);

            tmp.SearchProperties.Add("Id", "lst-ib");

            var txtEdit = new EnhancedHtmlEdit();

            txtEdit.WrapReady(tmp);
            txtEdit.SetText("Coded UI Test enhanced Framework");
            GoogleSearch pgSearch = WebPage.GetPage <GoogleSearch>();

            pgSearch.Close();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            // secret api key from https://serpapi.com/dashboard
            String apiKey = Environment.GetEnvironmentVariable("API_KEY");

            if (apiKey == null)
            {
                Console.WriteLine("API_KEY environment variable be set your secret api key visit: https://serpapi.com/dashboard");
                Environment.Exit(1);
            }

            // Localized search for Coffee shop in Austin Texas
            Hashtable ht = new Hashtable();

            ht.Add("q", "Coffee");
            ht.Add("hl", "en");
            ht.Add("google_domain", "google.com");

            GoogleSearch search = new GoogleSearch(ht, apiKey);

            try
            {
                Console.WriteLine("Get location matching: Austin");
                JArray locations = search.GetLocation("Austin,TX", 3);
                foreach (JObject location in locations)
                {
                    Console.WriteLine(location);
                }
                // set location
                search.parameterContext.Add("location", (string)locations[0]["canonical_name"]);

                Console.WriteLine("Search coffee in Austin, Texas on Google [1 credit]");
                JObject data = search.GetJson();
                Console.WriteLine("local coffee shop");
                JArray coffeeShops = (JArray)data["organic_results"];
                foreach (JObject coffeeShop in coffeeShops)
                {
                    Console.WriteLine("Found: " + coffeeShop["title"]);
                }
                Console.WriteLine("organic result coffee shop");
                coffeeShops = (JArray)data["organic_results"];
                foreach (JObject coffeeShop in coffeeShops)
                {
                    Console.WriteLine("Found: " + coffeeShop["title"]);
                }

                string id = (string)((JObject)data["search_metadata"])["id"];
                Console.WriteLine("Search from the archive: " + id + ". [0 credit]");
                JObject archivedSearch = search.GetSearchArchiveJson(id);
                foreach (JObject coffeeShop in (JArray)archivedSearch["organic_results"])
                {
                    Console.WriteLine("Found: " + coffeeShop["title"]);
                }

                //  Get account information
                Console.WriteLine("Account information: [0 credit]");
                JObject account = search.GetAccount();
                Dictionary <string, string> dictObj = account.ToObject <Dictionary <string, string> >();
                foreach (string key in dictObj.Keys)
                {
                    Console.WriteLine(key + " = " + dictObj[key]);
                }
                // write:
                // account_id = xx
                // api_key = xx
                // account_email = [email protected]
                // plan_id =
                // plan_name = No Plan
                // searches_per_month = 0
                // this_month_usage = 0
                // this_hour_searches = 1
                // last_hour_searches = 0
            }
            catch (SerpApiSearchException ex)
            {
                Console.WriteLine("Exception:");
                Console.WriteLine(ex.ToString());
            }
            // Close socket
            search.Close();
        }