コード例 #1
0
        public void FindByAlt()
        {
            var value = Find.ByAlt("alt text");

            Assert.IsInstanceOf(typeof(Constraint), value, "Alt class should inherit Attribute class");
            Assert.That(value.Comparer, Is.TypeOf(typeof(StringComparer)), "Unexpected comparer");

            const string name = "alt";

            Assert.AreEqual(name, value.AttributeName, "Wrong attributename");
            Assert.That(value.Comparer.ToString(), Text.Contains("'alt text'"), "Wrong value");

            var regex = new Regex("ext$");

            value = Find.ByAlt(regex);
            var mockAttributeBag = new MockAttributeBag(name, "alt text");
            var context          = new ConstraintContext();

            Assert.IsTrue(value.Matches(mockAttributeBag, context), "Regex ext$ should match");

            value = Find.ByAlt(new StringContainsAndCaseInsensitiveComparer("ALT TexT"));
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "Comparer not used");

            value = Find.ByAlt(text => text == "alt text");
            Assert.That(value.Matches(mockAttributeBag, context), Is.True, "PredicateComparer not used");
        }
コード例 #2
0
        /// <summary>
        /// Logins this instance.
        /// </summary>
        /// <returns></returns>
        public bool Login()
        {
            OpenUrl(UrlAccount);
            if (Browser.Image(Find.ByAlt("Персонаж")).Exists)
            {
                return(true);
            }


            Browser.TextField(Find.ByName("email")).Value    = AppCore.AcountSettings.Email;
            Browser.TextField(Find.ByName("passWord")).Value = AppCore.AcountSettings.Password;
            Browser.Image(Find.ByName("b_msg_go2")).Click();
            if ((Browser.Image(Find.ByAlt("Персонаж")).Exists))
            {
                return(true);
            }
            var cell = Browser.TableCell(Find.ByClass("text_msg"));

            if (cell.Exists)
            {
                AppCore.LogSystem.Error("Неможем зайти в ботву.", cell.Text);
            }

            return(false);
        }
コード例 #3
0
ファイル: ElementFinder.cs プロジェクト: gondar/coypu
        public WatiN.Core.Element FindButton(string locator, Scope scope)
        {
            var isButton = Constraints.OfType <Button>()
                           | Find.ByElement(e => e.TagName == "INPUT" && e.GetAttributeValue("type") == "image")
                           | Find.By("role", "button");

            var byText             = Find.ByText(locator);
            var byIdNameValueOrAlt = Find.ById(locator)
                                     | Find.ByName(locator)
                                     | Find.ByValue(locator)
                                     | Find.ByAlt(locator);
            var byPartialId = Constraints.WithPartialId(locator);
            var hasLocator  = byText | byIdNameValueOrAlt | byPartialId;

            var isVisible = Constraints.IsVisible(scope.ConsiderInvisibleElements);

            var candidates = WatiNScope(scope).Elements.Filter(isButton & hasLocator & isVisible);

            return(candidates.FirstMatching(byText, byIdNameValueOrAlt, byPartialId));
        }
コード例 #4
0
ファイル: LanguagesSteps.cs プロジェクト: misterPaul0/Curt
 public void WhenIClickLanguageIcon(string languageName)
 {
     IEInstance.Div(Find.ByClass("language-object")).Image(Find.ByAlt(languageName)).Click();
 }
コード例 #5
0
        static public Constraint GetConstraint(FindAttribute attribute)
        {
            string     findvalue  = attribute.FindValue;
            Constraint constraint = null;

            switch (attribute.FindMethod)
            {
            case FindMethods.Alt:
                constraint = Find.ByAlt(findvalue);
                break;

            case FindMethods.Class:
                constraint = Find.ByClass(findvalue);
                break;

            case FindMethods.For:
                constraint = Find.ByFor(findvalue);
                break;

            case FindMethods.Id:
                constraint = attribute.Regex ? Find.ById(new System.Text.RegularExpressions.Regex(findvalue)) : Find.ById(findvalue);
                break;

            case FindMethods.Index:
                try
                {
                    constraint = Find.ByIndex(Convert.ToInt32(findvalue));
                }
                catch {
                    MessageBox.Show(string.Format("值{0}格式不正确", findvalue));
                }
                break;

            case FindMethods.Name:
                constraint = attribute.Regex ? Find.ByName(new System.Text.RegularExpressions.Regex(findvalue)):Find.ByName(findvalue);
                break;

            case FindMethods.Src:
                constraint = Find.BySrc(findvalue);
                break;

            case FindMethods.Text:
                constraint = Find.ByText(findvalue);
                break;

            case FindMethods.Title:
                constraint = Find.ByTitle(findvalue);
                break;

            case FindMethods.Url:
                constraint = Find.ByUrl(findvalue);
                break;

            case FindMethods.Value:
                constraint = Find.ByValue(findvalue);
                break;

            case FindMethods.Href:
                constraint = attribute.Regex ? Find.By("href", new System.Text.RegularExpressions.Regex(findvalue)) : Find.By("href", findvalue);
                break;

            case FindMethods.Custom:
                constraint = Find.By(attribute.FindName, findvalue);
                break;

            case FindMethods.XPath:
                constraint = new XPathConstraint(findvalue);
                break;

            case FindMethods.ProximityText:
                constraint = new ProximityTextConstraint(findvalue);
                break;

            case FindMethods.CssSelector:
                constraint = Find.BySelector(findvalue);
                break;
            }

            return(constraint);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: Liyang-ing/ISB
        //按鈕按下開始查詢網內外
        public void btnGo_Click(object sender, EventArgs e)
        {
            label7.Text     = "";
            lblResult2.Text = "等待中...";
            //找尋最大id的指令
            string a = "select * from tel where id=(select max(id) from tel)";
            //與資料庫連線
            String          connString1 = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
            MySqlConnection conn1       = new MySqlConnection(connString1);
            MySqlCommand    command1    = conn1.CreateCommand();

            command1.CommandText = a.ToString();

            try
            {
                conn1.Open();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            MySqlDataReader reader1 = command1.ExecuteReader();

            while (reader1.Read())
            {
                j             = (int)reader1["id"];
                txtMaxId.Text = j.ToString();
            }
            conn1.Close();

            progressBar2.Maximum = j * 2;
            progressBar2.Value   = 0;
            progressBar2.Step    = 1;

            MessageBox.Show("程式開始,會關閉目前所有IE網頁,請準備好再按確定", "注意!");
            System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();

            //關閉所有的IE
            foreach (System.Diagnostics.Process myProcess in myProcesses)
            {
                if (myProcess.ProcessName.ToUpper() == "IEXPLORE")
                {
                    myProcess.Kill();
                }
            }


            //輸入網頁帳號密碼
            try
            {
                //將IE隱藏起來
                //browser.ShowWindow(NativeMethods.WindowShowStyle.Hide);
                browser.GoTo("http://www.emome.net/");
                browser.WaitForComplete();
                browser.Image(Find.ByAlt("登入")).Click();
                browser.TextField(Find.ById("uid")).TypeText("0920625964");
                browser.TextField(Find.ById("pw")).TypeText("288266");
                browser.Image(Find.ByAlt("登入會員")).Click();
                browser.WaitForComplete();
                //到網內外判斷網站,開始辨別網內外
                browser.GoTo("http://auth.emome.net/emome/membersvc/AuthServlet?serviceId=mobilebms&url=qryTelnum.jsp");
                browser.WaitForComplete();
            }

            catch
            {
                MessageBox.Show("網頁異常,請稍後再試!");
            }



            //藉由"id"欄位取得資料庫內的號碼
            for (i = 1; i <= j; i++)
            {
                progressBar2.Value += progressBar2.Step;
                string          getting    = "Select number from tel where id = " + i + "";
                String          connString = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
                MySqlConnection conn       = new MySqlConnection(connString);
                MySqlCommand    command    = conn.CreateCommand();
                command.CommandText = getting.ToString();
                txtId.Text          = i.ToString();

                try
                {
                    conn.Open();
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }


                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    txtNumber.Text = reader["number"].ToString();
                }

                //判斷是否還有需要辨別的號碼
                if (txtNumber.Text != "Finding...")
                {
                    browser.TextField(Find.ById("telnum")).TypeText(txtNumber.Text.Trim());
                    browser.Button(Find.ById("btn_submit")).Click();
                    conn.Close();
                    browser.WaitForComplete();

                    try
                    {
                        string myHtml = browser.Body.Parent.OuterHtml;
                        string result = myHtml;
                        int    first  = result.IndexOf("您所查詢之行動門號");
                        int    last   = result.LastIndexOf("為「");
                        string cut1   = result.Substring(first + 21, last - first - 17);
                        if (cut1 == "網內")
                        {
                            txtResult.Text = txtNumber.Text + "  此號碼為中華電信";
                            string          b           = "Update tel SET ope='c' WHERE id='" + i + "'";
                            String          connString2 = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
                            MySqlConnection conn2       = new MySqlConnection(connString2);
                            MySqlCommand    command2    = conn2.CreateCommand();
                            command2.CommandText = b.ToString();

                            try
                            {
                                conn2.Open();
                            }

                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                            MySqlDataReader reader2 = command2.ExecuteReader();
                            while (reader2.Read())
                            {
                                ;
                            }
                            conn2.Close();
                        }
                        else
                        {
                            txtResult.Text = txtNumber.Text + "  此號碼並不是中華電信";
                            string          b           = "Update tel SET ope='n' WHERE id='" + i + "'";
                            String          connString2 = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
                            MySqlConnection conn2       = new MySqlConnection(connString2);
                            MySqlCommand    command2    = conn2.CreateCommand();
                            command2.CommandText = b.ToString();

                            try
                            {
                                conn2.Open();
                            }

                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                            MySqlDataReader reader2 = command2.ExecuteReader();
                            while (reader2.Read())
                            {
                                ;
                            }
                            conn2.Close();
                        }
                    }
                    catch
                    {
                        //MessageBox.Show(ex.Message);
                    }
                    txtNumber.Text = "中華電信判斷結束";
                }
            }
            if (txtNumber.Text == "中華電信判斷結束")
            {
                browser.GoTo("http://www.fetnet.net/ecare/eService/web/public/forwardController.do?forwardPage=ucs/queryNetworkType/esqnt01&csType=cs");
                browser.WaitForComplete();
                for (int aj = 1; aj <= j; aj++)
                {
                    progressBar2.Value += progressBar2.Step;
                    string          getting    = "Select ope from tel where id = " + aj + "";
                    String          connString = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
                    MySqlConnection conn       = new MySqlConnection(connString);
                    MySqlCommand    command    = conn.CreateCommand();
                    command.CommandText = getting.ToString();
                    txtId.Text          = aj.ToString();

                    try
                    {
                        conn.Open();
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }


                    MySqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        txtOpe.Text = reader["ope"].ToString();
                    }
                    conn.Close();

                    if (txtOpe.Text == "n")
                    {
                        string          getnum      = "Select number from tel where id = " + aj + "";
                        String          connString3 = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
                        MySqlConnection conn3       = new MySqlConnection(connString3);
                        MySqlCommand    command3    = conn3.CreateCommand();
                        command3.CommandText = getnum.ToString();

                        try
                        {
                            conn3.Open();
                        }

                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }


                        MySqlDataReader reader3 = command3.ExecuteReader();
                        while (reader3.Read())
                        {
                            txtNumber.Text = reader3["number"].ToString();
                        }

                        try
                        {
                            browser.TextField("msisdn").TypeText(txtNumber.Text);
                            browser.Button(Find.ById("queryButton")).Click();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                        try
                        {
                            string myHtml2 = browser.Body.Parent.OuterHtml;
                            string result2 = myHtml2;
                            int    first2  = result2.IndexOf("「<font color=");
                            int    last2   = result2.LastIndexOf("</font>」門號");
                            string cut2    = result2.Substring(first2 + 19, last2 - first2 - 19);
                            if (cut2 == "網內")
                            {
                                txtResult.Text = txtNumber.Text + "  此號碼為遠傳電信";
                                string          b           = "Update tel SET ope='f' WHERE id='" + aj + "'";
                                String          connString2 = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
                                MySqlConnection conn2       = new MySqlConnection(connString2);
                                MySqlCommand    command2    = conn2.CreateCommand();
                                command2.CommandText = b.ToString();

                                try
                                {
                                    conn2.Open();
                                }

                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                                MySqlDataReader reader2 = command2.ExecuteReader();
                                while (reader2.Read())
                                {
                                    ;
                                }
                                conn2.Close();
                            }
                            else
                            {
                                txtResult.Text = txtNumber.Text + "  此號碼並不是遠傳電信";
                                string          b           = "Update tel SET ope='n' WHERE id='" + aj + "'";
                                String          connString2 = "Server=localhost;Port=3306;Database=data;uid=root;password=288266;";
                                MySqlConnection conn2       = new MySqlConnection(connString2);
                                MySqlCommand    command2    = conn2.CreateCommand();
                                command2.CommandText = b.ToString();

                                try
                                {
                                    conn2.Open();
                                }

                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                                MySqlDataReader reader2 = command2.ExecuteReader();
                                while (reader2.Read())
                                {
                                    ;
                                }
                                conn2.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
            browser.Close();
            txtNumber.Text      = "號碼已查詢完畢";
            btnGo.Enabled       = false;
            lblResult2.Text     = "成功!";
            btnSendBack.Enabled = true;
        }