public void ClickShouldWork() { string fieldname = "somefieldname"; mockProcessor.ExpectAndReturn("DoCommand", "OK", new object[] { "click", new string[] { fieldname } }); selenium.Click(fieldname); }
public void SearchAndWaitBySeleniumRemoteControl() { //not working on latest IE and FireFox versions ISelenium sel = new DefaultSelenium("localhost", 4444, "*iehta", "http://www.google.com"); sel.Start(); sel.Open("http://www.google.com/"); sel.Type("q", "FitNesse"); sel.Click("btnG"); sel.WaitForPageToLoad("3000"); }
///<summary> ///Recursive Method, recall this method when timeout or other errors happend ///Call PDFAnalysis method to download PDF from from http://www.hkexnews.hk/listedco/listconews/advancedsearch/search_active_main.asp ///and extract data from PDF by specific stock code ///</summary> ///<param name="index">ricList index</param> ///<returns> void </returns> private void DataCaptureFromPDF(int index) { ISelenium pdfSearch1 = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.hkexnews.hk"); int start_position = index; pdfSearch1.Start(); try { pdfSearch1.Open("/listedco/listconews/advancedsearch/search_active_main.asp"); pdfSearch1.WaitForPageToLoad("60000"); for (; start_position < ricList.Count; start_position++) { pdfSearch1.Type("txt_stock_code", ricList[start_position].ricCodeStr); pdfSearch1.Click("//table[@id='Table1']/tbody/tr[3]/td/table[2]/tbody/tr/td/table/tbody/tr[14]/td[3]/label/a[1]/img"); pdfSearch1.WaitForPageToLoad("30000"); String pdfUrl = pdfSearch1.GetAttribute("//table[@id='Table4']/tbody/tr[8]/td/table/tbody/tr[3]/td[4]/table/tbody/tr/td/a@href"); pdfList.Add(coreObj.PDFAnalysis(pdfUrl, ricList[start_position].ricCodeStr)); pdfSearch1.Click("//table[@id='Table5']/tbody/tr/td/table/tbody/tr/td[1]/a/img"); pdfSearch1.WaitForPageToLoad("30000"); } pdfSearch1.Close(); pdfSearch1.Stop(); } catch (Exception ex) { String errLog = ex.ToString(); coreObj.WriteLogFile(errLog); coreObj.WriteLogFile(ricList[start_position].ricCodeStr); coreObj.WriteLogFile("start_position=" + start_position); pdfSearch1.Close(); pdfSearch1.Stop(); DataCaptureFromPDF(start_position); } }
//public static string GetDynamicPageSource(string uri, int timeout, string postData, string cookie) //{ // string pageSource = string.Empty; // Encoding encoding = Encoding.UTF8; // byte[] buf = null; // int retryiesLeft = 5; // buf = encoding.GetBytes(postData); // while (string.IsNullOrEmpty(pageSource) && retryiesLeft-- > 0) // { // HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest; // request.Timeout = timeout; // request.Headers["Cookie"] = cookie; // request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"; // request.Method = "POST"; // request.ContentType = "application/x-www-form-urlencoded"; // request.ContentLength = buf.Length; // request.GetRequestStream().Write(buf, 0, buf.Length); // using (WebResponse response = request.GetResponse()) // { // StreamReader sr = new StreamReader(response.GetResponseStream()); // pageSource = sr.ReadToEnd(); // } // } // if (pageSource == string.Empty) // { // throw new Exception(string.Format("Cannot download page {0}b with post data {1}", uri, postData)); // } // return pageSource; //} //public static HttpWebResponse GetResponse(string uri, int timeout, string postData) //{ // string pageSource = string.Empty; // Encoding encoding = Encoding.UTF8; // byte[] buf = null; // buf = encoding.GetBytes(postData); // HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest; // request.Timeout = timeout; // //request.Headers["Cookie"] = "80922B3FB48D76DD2F6A268906563EC5.simpn9; Path=/ism"; // request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"; // request.Method = "POST"; // request.ContentType = "application/x-www-form-urlencoded"; // request.ContentLength = buf.Length; // request.GetRequestStream().Write(buf, 0, buf.Length); // return request.GetResponse() as HttpWebResponse; //} //private void DataCaptureFromSetSmart(string symbol) //{ // string loginUrl = "http://www.setsmart.com/ism/login.jsp"; // string loginPostData = "txtLogin=25932633&txtPassword=reuters1&hidBrowser=null&hidLang=English"; // string searchUrl = "http://www.setsmart.com/ism/companyprofile.html"; // string searchData = "symbol=" + symbol; // var req = GetResponse(loginUrl, 10000, loginPostData); // var cookie = req.Headers["Set-Cookie"]; // cookie = cookie.Substring(0, cookie.IndexOf(";")).Trim(); // var content = GetDynamicPageSource(searchUrl, 10000, searchData, cookie); //} /** * Grab Data from http://isin.krx.co.kr/ * */ //private void DataCaptureFromSET() //{ // String symbolType = "SET"; // int startPosition = configObj.start_position; // int endPosition = configObj.end_position; // try // { // selenium.SetTimeout("50000"); // selenium.OpenWindow("/set/todaynews.do?language=en&country=US", "parentWindow"); // selenium.WaitForPopUp("parentWindow", "50000"); // selenium.SelectWindow("parentWindow"); // //No defination for searching end of position // if (configObj.end_position == 0) // { // while (selenium.IsElementPresent("//tr[2]/td/table/tbody/tr[" + startPosition + "]/td[3]")) // { // String symbolStr = selenium.GetText("//tr[2]/td/table/tbody/tr[" + startPosition + "]/td[3]"); // if (symbolStr == symbolType) // { // String headlineStr = selenium.GetText("//tr[2]/td/table/tbody/tr[" + startPosition + "]/td[4]"); // if (headlineStr.Contains("adds new") && (headlineStr.Contains("CC") || headlineStr.Contains("CB") || headlineStr.Contains("CA") || headlineStr.Contains("CD") || headlineStr.Contains("CE") || headlineStr.Contains("CF"))) // { // String htmlUrl = selenium.GetAttribute("//tr[2]/td/table/tbody/tr[" + startPosition + "]/td[5]/a[text()='HTML']@href"); // selenium.OpenWindow(htmlUrl, "detailWindow" + startPosition); // selenium.WaitForPopUp("detailWindow" + startPosition, "10000"); // selenium.SelectWindow("detailWindow" + startPosition); // String txtFile = selenium.GetText("//pre"); // //here call txt analysis method // DataAnalysis(txtFile); // count++; // selenium.SelectWindow("parentWindow"); // } // } // startPosition = startPosition + 2; // }//end while // } // else if (configObj.end_position >= configObj.start_position) // { // for (int i = startPosition; i <= endPosition; i = i + 2) // { // String symbolStr = selenium.GetText("//tr[2]/td/table/tbody/tr[" + startPosition + "]/td[3]"); // if (symbolStr == symbolType) // { // String headlineStr = selenium.GetText("//tr[2]/td/table/tbody/tr[" + startPosition + "]/td[4]"); // if (headlineStr.Contains("adds new") && (headlineStr.Contains("CC") || headlineStr.Contains("CB") || headlineStr.Contains("CA") || headlineStr.Contains("CD") || headlineStr.Contains("CE") || headlineStr.Contains("CF"))) // { // String htmlUrl = selenium.GetAttribute("//tr[2]/td/table/tbody/tr[" + startPosition + "]/td[5]/a[text()='HTML']@href"); // selenium.OpenWindow(htmlUrl, "detailWindow" + startPosition); // selenium.WaitForPopUp("detailWindow" + startPosition, "10000"); // selenium.SelectWindow("detailWindow" + startPosition); // String txtFile = selenium.GetText("//pre"); // //here call txt analysis method // DataAnalysis(txtFile); // count++; // selenium.SelectWindow("parentWindow"); // } // } // }//end for // }//end else if // else // { // logger.LogErrorAndRaiseException("end_position must bigger than start_position"); // } // }//end try // catch (SeleniumException e) // { // logger.LogErrorAndRaiseException(e.ToString()); // ClearTest(); // } //}//end DataCaptureFromSET() /** * Get ISIN number from http://isin.krx.co.kr by specific official code * */ private String DataCaptureFromSetSmart(String officialCode) { ISelenium setsmart = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.setsmart.com"); try { setsmart.Start(); setsmart.UseXpathLibrary("javascript-xpath"); setsmart.Open("/ism/login.jsp"); setsmart.WaitForPageToLoad("60000"); setsmart.Type("txtLogin", configObj.username); setsmart.Type("txtPassword", configObj.password); setsmart.Click("//input[@type='image']"); //setsmart.Click("//input[@type='image' and @onclick='return validate();']"); setsmart.WaitForPageToLoad("60000"); setsmart.Click("link=Company Profile"); setsmart.WaitForPageToLoad("60000"); setsmart.Type("symbol", officialCode); setsmart.Click("//input[@type='image']"); //setsmart.Click("//input[@name='submit' and @value='go' and @type='image' and @onclick=' return validateSubmit(); ']"); System.Threading.Thread.Sleep(3000); String isinNumber = setsmart.GetText("//table[3]/tbody/tr[26]/td[2]"); setsmart.Click("link=LOGOUT"); setsmart.Stop(); //return isinNumber.Substring(isinNumber.IndexOf("Local") + 8, isinNumber.IndexOf("Foreign") - 9); return(isinNumber.Substring(isinNumber.IndexOf("Local") + 7, isinNumber.Length - isinNumber.IndexOf("Local") - 7)); } catch (SeleniumException e) { setsmart.Stop(); logger.LogErrorAndRaiseException(e.ToString()); return(e.ToString()); } }