Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //var calc = new Winium.Cruciatus.Application(@"C:\dev\svn\trunk\Trash\Trash\011Winium.Cruciatus試し\TestForm\bin\Debug\TestForm.exe");
            //calc.Start();
            //var winFinder = By.Name("Form1").AndType(ControlType.Window);
            //var win = Winium.Cruciatus.CruciatusFactory.Root.FindElement(winFinder);


            ////電卓の'5','6','7'ボタンクリック
            ////AutomationId指定
            ////win.FindElementByName("button1").Click();

            //win.FindElementByUid("button1").Click();
            //win.FindElementByUid("button2").Click();
            //win.FindElementByUid("button3").Click();

            ////Console.Write("Press any key to continue . . . ");
            ////Console.ReadKey(true);

            //var calc = new Winium.Cruciatus.Application("C:/windows/system32/calc.exe");
            //calc.Start();

            //var winFinder = By.Name("電卓").AndType(ControlType.Window);
            //var win = Winium.Cruciatus.CruciatusFactory.Root.FindElement(winFinder);
            ////var menu = win.FindElementByUid("Menubar").ToMenu();

            ////menu.SelectItem("関数電卓");
            ////menu.SelectItem("履歴");

            //win.FindElementByUid("132").Click(); // 2
            //                                     //win.FindElementByUid("93").Click(); // +
            //                                     //win.FindElementByUid("134").Click(); // 4
            //                                     //win.FindElementByUid("97").Click(); // ^
            //                                     //win.FindElementByUid("138").Click(); // 8
            //                                     //win.FindElementByUid("121").Click(); // =

            //calc.Close();

            var calc = new Winium.Cruciatus.Application(@"C:\Windows\System32\calc.exe");

            calc.Start();
            var winFinder = By.Name("電卓").AndType(ControlType.Window);
            var win       = Winium.Cruciatus.CruciatusFactory.Root.FindElement(winFinder);

            //電卓の'5','6','7'ボタンクリック
            //AutomationId指定
            win.FindElementByUid("num5Button").Click();
            win.FindElementByUid("num6Button").Click();
            win.FindElementByUid("num7Button").Click();

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var calc = new Winium.Cruciatus.Application(@"C:\Windows\System32\calc.exe");

            calc.Start();
            var winFinder = By.Name("電卓").AndType(ControlType.Window);
            var win       = Winium.Cruciatus.CruciatusFactory.Root.FindElement(winFinder);

            //電卓の'5','6','7'ボタンクリック
            //AutomationId指定
            win.FindElementByUid("num5Button").Click();
            win.FindElementByUid("num6Button").Click();
            win.FindElementByUid("num7Button").Click();

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Пример #3
0
        private void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            SelectChangedSource = UiSelectChangedSource.SelectChangeFinished;

            if (IsRecording == false)
            {
                try
                {
                    //Start Application Under Test
                    var app = new Winium.Cruciatus.Application(txtAppAddress.Text);
                    app.Start();

                    //******

                    MouseKeyboardEventHandler.Init();

                    btnRecord.Content            = "Pause";
                    textBoxRecording.Text        = "Recording";
                    gridTextRecording.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));

                    IsRecording = true;
                    AppInsights.LogEvent("Record");
                }
                catch (Exception)
                {
                    MessageBox.Show("The application under test does not exists");
                }
            }
            else
            {
                IsRecording = false;

                MouseKeyboardEventHandler.UnInit();

                btnRecord.Content            = "Start";
                textBoxRecording.Text        = "";
                gridTextRecording.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF));

                AddInspectUi(null); // remove last Inspect node
                AppInsights.LogEvent("Pause");
            }
        }
Пример #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            var calc = new Winium.Cruciatus.Application("C:/windows/system32/calc.exe");

            calc.Start();

            var winFinder = By.Name("Calculator").AndType(ControlType.Window);
            var win       = Winium.Cruciatus.CruciatusFactory.Root.FindElement(winFinder);
            var menu      = win.FindElementByUid("MenuBar").ToMenu();

            menu.SelectItem("View$Scientific");
            menu.SelectItem("View$History");

            win.FindElementByUid("132").Click(); // 2
            win.FindElementByUid("93").Click();  // +
            win.FindElementByUid("134").Click(); // 4
            win.FindElementByUid("97").Click();  // ^
            win.FindElementByUid("138").Click(); // 8
            win.FindElementByUid("121").Click(); // =

            calc.Close();
        }
Пример #5
0
        public void TestTrue()
        {
            var calc = new Winium.Cruciatus.Application("C:/windows/system32/calc.exe");

            calc.Start();
            var winFinder = By.Name("Калькулятор").AndType(ControlType.Window);
            var window    = Winium.Cruciatus.CruciatusFactory.Root.FindElement(winFinder);//Инициализатор типа "Winium.Cruciatus.CruciatusFactory" выдал исключение.


            Random rnd       = new Random();
            int    value     = rnd.Next(1, 100);
            string strVal    = Convert.ToString(value);
            var    textField = window.FindElementByUid("150");

            textField.Click();
            textField.SetText(strVal);//шаг2

            /*
             * String strVal="", strVal1 = "", strVal2="";
             * Random rnd = new Random();
             * int value = rnd.Next(1, 100); //ввод кнопками
             * if (value >= 10)
             * {
             *  strVal = Convert.ToString(value);
             *  strVal1 = strVal.Substring(0,1);
             *  strVal1 = "13" + strVal1;
             *  window.FindElementByUid(strVal1);
             *  strVal2 = strVal.Substring(1,1);
             *  strVal2 = "13" + strVal2;
             *  window.FindElementByUid(strVal2);
             *
             * }
             * else {
             *  strVal = Convert.ToString(value);
             *  strVal = "13" + strVal;
             *  window.FindElementByUid(strVal);
             *
             * }
             */
            window.FindElementByUid("110").Click();//кнопка_корень
            var    textField2 = window.FindElementByUid("404");
            string sravn      = "sqrt(" + value + ")";

            string sravnField = textField2.Text();

            if (sravn == sravnField)
            {
                Console.WriteLine("Операция отображена верно");//шаг3
            }
            strVal = textField.Text();
            double valField = Convert.ToDouble(strVal);

            double valSqrt = Math.Sqrt(value);

            if (valField == valSqrt)
            {
                Console.WriteLine("Корни равны");//шаг4
            }
            window.FindElementByUid("92").Click();
            window.FindElementByUid("121").Click();
            strVal = textField.Text();
            if (value == Convert.ToInt32(strVal))
            {
                Console.WriteLine("Число из которого вычисляли корень");
            }                                                            //шаг5
            calc.Close();

            /*
             * var dc = new DesiredCapabilities();
             * dc.SetCapability("app", @"C:/windows/system32/calc.exe");
             * var driver = new RemoteWebDriver(new Uri("https://localhost:9999"), dc);
             * var window = driver.FindElementByClassName("CalcFrame");
             *
             * Random rnd = new Random();
             * int value = rnd.Next(1, 100); //добавить ввод кнопками
             * string valStr=Convert.ToString(value);
             *
             * var textField =window.FindElement(OpenQA.Selenium.By.Id("150"));
             * textField.Click();
             * textField.SendKeys(strVal);//шаг2
             * window.FindElement(OpenQA.Selenium.By.Id("110")).Click(); //кнопка_корень
             * var textField2 = window.FindElement(OpenQA.Selenium.By.Id("404"));
             * string sravn = "sqrt(" + value + ")";
             *
             * string sravnField = textField2.Text();//()
             * if (sravn == sravnField)
             *  Console.WriteLine("Операция отображена верно");//шаг3
             *
             *
             * valStr = textField.Text;
             * double valField = Convert.ToDouble(strVal);
             *
             * double valSqrt = Math.Sqrt(value);
             * if (valField == valSqrt)
             *  Console.WriteLine("Корни равны");//шаг4
             * window.FindElement(OpenQA.Selenium.By.Id("92")).Click();//кнопка_умножения
             * window.FindElement(OpenQA.Selenium.By.Id("121")).Click();//кнопка_равно
             * strVal = textField.Text;
             * if (value == Convert.ToInt32(strVal))
             * { Console.WriteLine("Число из которого вычисляли корень"); }
             * driver.Quit();
             *
             */
        }
Пример #6
0
        public static void Main(string[] args)
        {
            int        index     = -1;
            var        actions   = ConfigurationManager.GetSection("ActionSequence/Actions") as NameValueCollection;
            ByProperty winFinder = null;

            Winium.Cruciatus.Elements.CruciatusElement win = null;
            bool fault = false;

            foreach (var action in actions.AllKeys)
            {
                if (fault)
                {
                    break;      // exit out of the loop in case of fault.
                }
                if (action.Contains("ExecutablePath"))
                {
                    try
                    {
                        string appPath = actions[action];
                        var    cm      = new Winium.Cruciatus.Application(appPath);
                        cm.Start();
                        Console.WriteLine("\nExecutable Started : " + actions[action]);
                    }
                    catch (Exception ex)
                    {
                        fault = true;
                        Console.WriteLine("\nExecutable could not be started : " + actions[action]);
                        Console.WriteLine("\n\n" + ex.Message + "\n");
                        Console.WriteLine(ex.ToString());
                    }
                }
                if (action.Contains("WinFinder"))
                {
                    try
                    {
                        winFinder = By.Name(actions[action]).AndType(ControlType.Window);
                        win       = Winium.Cruciatus.CruciatusFactory.Root.FindElement(winFinder);
                        Console.WriteLine("\nWindow Found : " + actions[action]);
                    }
                    catch (Exception ex)
                    {
                        fault = true;
                        Console.WriteLine("\nWindow not Found : " + actions[action]);
                        Console.WriteLine("\n\n" + ex.Message + "\n");
                        Console.WriteLine(ex.ToString());
                    }
                }
                if (action.Contains("FindElementByUid"))
                {
                    try
                    {
                        var element = win.FindElementByUid(actions[action]);
                        Console.WriteLine("\nFindElementByUid found : " + actions[action]);
                        element.Click();
                    }
                    catch (Exception ex)
                    {
                        fault = true;
                        Console.WriteLine("\nFindElementByUid not Found : " + actions[action]);
                        Console.WriteLine("\n\n" + ex.Message + "\n");
                        Console.WriteLine(ex.ToString());
                    }
                }
                if (action.Contains("FindElementByName"))
                {
                    try
                    {
                        var element = win.FindElementByName(actions[action]);
                        Console.WriteLine("\nElementByName found : " + actions[action]);
                        element.Click();
                    }
                    catch (Exception ex)
                    {
                        fault = true;
                        Console.WriteLine("\nElementByName not Found : " + actions[action]);
                        Console.WriteLine("\n\n" + ex.Message + "\n");
                        Console.WriteLine(ex.ToString());
                    }
                }
                if (action.Contains("Wait"))
                {
                    Console.WriteLine("\nWaiting for " + actions[action] + " seconds");
                    System.Threading.Thread.Sleep(Convert.ToInt32(actions[action]) * 1000);
                }

                if (action.Contains("SetFocus"))
                {
                    try
                    {
                        var element = win.FindElementByUid(actions[action]);
                        Console.WriteLine("\nSetFocus found : " + actions[action]);
                        element.SetFocus();
                    }
                    catch (Exception ex)
                    {
                        fault = true;
                        Console.WriteLine("\nSetFocus not Found : " + actions[action]);
                        Console.WriteLine("\n\n" + ex.Message + "\n");
                        Console.WriteLine(ex.ToString());
                    }
                }
                if (action.Contains("SetFocusByName"))
                {
                    try
                    {
                        var element = win.FindElementByName(actions[action]);
                        Console.WriteLine("\nSetFocusByName found : " + actions[action]);
                        element.SetFocus();
                    }
                    catch (Exception ex)
                    {
                        fault = true;
                        Console.WriteLine("\nSetFocusByName not Found : " + actions[action]);
                        Console.WriteLine("\n\n" + ex.Message + "\n");
                        Console.WriteLine(ex.ToString());
                    }
                }
                if (action.Contains("SetText"))
                {
                    try
                    {
                        if (0 != args.Length)
                        {
                            var element = win.FindElementByUid(actions[action]);
                            Console.WriteLine("\nSetText found : " + actions[action]);
                            element.SetText(args[++index]);
                        }
                        else
                        {
                            var controlAndTextArray = Regex.Split(actions[action], @";#");
                            if (controlAndTextArray.Length > 1)
                            {
                                var element = win.FindElementByUid(controlAndTextArray[0]);
                                Console.WriteLine("\nSetText found : " + actions[action]);
                                element.SetText(controlAndTextArray[1]);
                            }
                            else
                            {
                                var element = win.FindElementByUid(actions[action]);
                                Console.WriteLine("\nSetText found : " + actions[action]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        fault = true;
                        Console.WriteLine("\nSetText not Found : " + actions[action]);
                        Console.WriteLine("\n\n" + ex.Message + "\n");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            if (fault)
            {
                Console.WriteLine("\n\nSome fault has occured.");
            }
            else
            {
                Console.WriteLine("\n\nAutomation happened successfully.");
            }
            Console.ReadLine();
        }