public void RegisterFemaleSns() { Thread.Sleep(1000); dynamic window = _app.Type <Application>().Current.MainWindow; var nameTextBox = new WPFTextBox(window.Name); nameTextBox.EmulateChangeText("Peach"); Thread.Sleep(1000); var sexRadio = new WPFButtonBase(window.Female); sexRadio.EmulateClick(); Thread.Sleep(1000); var reasonComboBox = new WPFComboBox(window.Reason); reasonComboBox.EmulateChangeSelectedIndex(2); Thread.Sleep(1000); var registerBtn = new WPFButtonBase(window.RegisterBtn); registerBtn.EmulateClick(); var outputTxtBlock = new WPFTextBlock(window.Output); Assert.AreEqual(outputTxtBlock.Text.Replace("\n", ""), $"登録者名: Peach\n性別: 女性\n登録する経緯: SNSで見た".Replace("\n", "")); Thread.Sleep(1000); }
public MainViewDirver(dynamic mainView) { var w = new WindowControl(mainView); //指定のオブジェクトを起点とした //ロジカルツリー中にあるLhsというパスにバインドされている要素のコレクション //Identifyは一つだけであることを保障する //コレクションの要素が1以外だった場合は例外発生 w.LogicalTree().ByBinding("Lhs").Identify(); //ビジュアルツリーでは、こんな感じで書く w.VisualTree().ByBinding("Lhs").Identify(); //データアイテムを指定して、さらに厳密な指定にできる var dataItem = new ExplicitVar(w.Dynamic().DataContext); w.LogicalTree().ByBinding("Lhs", dataItem).Identify(); Lhs = new WPFTextBox(w.LogicalTree().ByBinding("Lhs").Identify()); CalculateTypes = new WPFComboBox(w.LogicalTree().ByBinding("CalculateTypes").Identify()); Rhs = new WPFTextBox(w.LogicalTree().ByBinding("Rhs").Identify()); CalculateCommand = new WPFButtonBase(w.LogicalTree().ByBinding("CalculateCommand").Identify()); Answer = w.LogicalTree().ByBinding("Answer").Identify().Dynamic(); }
public TestDriver(WindowControl w) { MainWindow = w; LogicalTree = w.LogicalTree(); cmbMode = new WPFComboBox(LogicalTree.ByType <ComboBox>().Single()); txtInputText = new WPFTextBox(LogicalTree.ByType <TextBox>().Single()); grdHiragana = new WPFGrid(w.AppVar["FindName"].Invoke("grdHiragana")); grdKatakana = new WPFGrid(w.AppVar["FindName"].Invoke("grdKatakana")); }
public void TestInitialize() { app = new WindowsAppFriend(Process.Start("Target.exe")); WindowsAppExpander.LoadAssembly(app, GetType().Assembly); dynamic win = app.Type(typeof(Application)).Current.MainWindow; dynamic grid = win._grid; dynamic target = app.Type<ComboBox>()(); grid.Children.Add(target); target.ItemsSource = Enumerable.Range(0, 100).Select(i => "value " + i).ToArray(); target.IsEditable = true; target.IsReadOnly = false; comboBox = new WPFComboBox(target); }
public void TestInitialize() { app = new WindowsAppFriend(Process.Start("Target.exe")); WindowsAppExpander.LoadAssembly(app, GetType().Assembly); dynamic win = app.Type(typeof(Application)).Current.MainWindow; dynamic grid = win._grid; dynamic target = app.Type <ComboBox>()(); grid.Children.Add(target); target.ItemsSource = Enumerable.Range(0, 100).Select(i => "value " + i).ToArray(); target.IsEditable = true; target.IsReadOnly = false; comboBox = new WPFComboBox(target); }
public void Clear() { dynamic window = _app.Type <Application>().Current.MainWindow; var nameTextBox = new WPFTextBox(window.Name); nameTextBox.EmulateChangeText(string.Empty); var sexRadio = new WPFButtonBase(window.Male); sexRadio.EmulateClick(); var reasonComboBox = new WPFComboBox(window.Reason); reasonComboBox.EmulateChangeSelectedIndex(-1); }
public void コントロール特定() { AppVar main = _app.Type <Application>().Current.MainWindow; var userControl = main.LogicalTree().ByType("WpfApplication.DemoSimpleControl").Single(); var logicalTree = userControl.LogicalTree(); var textBoxX = new WPFTextBox(userControl.Dynamic()._textBox); var textBoxMail = new WPFTextBox(logicalTree.ByBinding("Mail").Single()); var comboBoxxLanguage = new WPFComboBox(logicalTree.ByBinding("Language").Single()); var buttons = userControl.LogicalTree().ByType <Button>(); var buttonOpen = new WPFButtonBase(buttons.ByCommand(ApplicationCommands.Open).Single()); var button1 = new WPFButtonBase(buttons.ByCommandParameter("1").Single()); var buttonA = new WPFButtonBase(buttons.ByCommandParameter((AppVar)_app.Type().WpfApplication.EnumPram.A).Single()); var buttonCancel = new WPFButtonBase(buttons.ByIsCancel().Single()); }
public void SelectedFundIsAddedOnlyToTheSelectedCustomer() { string[] selectedCustomer = new string[2]; string[] selectedFund = new string[2]; const int CUSTOMERS_IN_DROPDOWN = 2; for (int i = 0; i < CUSTOMERS_IN_DROPDOWN; i++) { //Get the handle of the Customer combo box and select customer. WPFComboBox customer = Window.Get <WPFComboBox>(TestDataInfrastructure.GetControlId("CustomerCombobox")); customer.Select(TestDataInfrastructure.GetTestInputData("Customer" + i.ToString(CultureInfo.InvariantCulture)).ToString()); selectedCustomer[i] = customer.Items[i].Text; //Get the handle of the Fund combo box and select fund. WPFComboBox fund = Window.Get <WPFComboBox>(TestDataInfrastructure.GetControlId("FundCombobox")); fund.Select(TestDataInfrastructure.GetTestInputData("Fund" + i.ToString(CultureInfo.InvariantCulture))); selectedFund[i] = fund.Items[i].Text; //Get the handle of the Add button and click on it. Button addButton = Window.Get <Button>(TestDataInfrastructure.GetControlId("AddButton")); addButton.Click(); } // Now validate whether the fund has been added correctly. List <AutomationElement> elements = Window.AutomationElement.FindSiblingsInTreeByName("ActivityView"); int counter = 0; foreach (AutomationElement element in elements) { if (counter < CUSTOMERS_IN_DROPDOWN) { // Find the text box and the fund text associated. AutomationElement textBox = element.SearchInRawTreeByName("ActivityLabel"); string textBoxValue = textBox.Current.Name; string expectedValue = TestDataInfrastructure.GetTestInputData("ActivityLabelText") + selectedCustomer[counter].ToString(); Assert.AreEqual(expectedValue, textBoxValue); // Find the fund values AutomationElement fund = element.SearchInRawTreeByName(selectedFund[counter].ToString()); Assert.AreEqual(fund.Current.Name, selectedFund[counter].ToString()); counter++; } } }
private void ValidateBuySellPanelData(Order model) { SelectBuySellTabPage(); TextBox symbolTextBox = Window.Get <TextBox>(TestDataInfrastructure.GetControlId("BuySellSymbolTextBox")); Assert.AreEqual(model.Symbol, symbolTextBox.Text); if (!String.IsNullOrEmpty(model.OrderType)) { WPFComboBox orderTypeComboBox = Window.Get <WPFComboBox>(TestDataInfrastructure.GetControlId("BuySellOrderTypeCombo")); Assert.AreEqual(model.OrderType, orderTypeComboBox.SelectedItem.Text); } TextBox shareTextBox = Window.Get <TextBox>(TestDataInfrastructure.GetControlId("BuySellSharesTextBox")); Assert.AreEqual(model.NumberOfShares.ToString(CultureInfo.CurrentCulture), shareTextBox.Text); TextBox limitStopPriceTextBox = Window.Get <TextBox>(TestDataInfrastructure.GetControlId("BuySellStopLimitPriceTextBox")); Assert.AreEqual(model.LimitStopPrice.ToString(CultureInfo.CurrentCulture), limitStopPriceTextBox.Text); if (!String.IsNullOrEmpty(model.TimeInForce)) { WPFComboBox timeInForceComboBox = Window.Get <WPFComboBox>(TestDataInfrastructure.GetControlId("BuySellTimeInForceCombo")); Assert.AreEqual(timeInForceComboBox.SelectedItem.Text, model.FormattedTimeInForce); } switch (model.TransactionType) { case "Buy": RadioButton buyRadButton = Window.Get <RadioButton>(TestDataInfrastructure.GetControlId("BuyRadio")); Assert.IsTrue(buyRadButton.IsSelected); break; case "Sell": RadioButton sellRadButton = Window.Get <RadioButton>(TestDataInfrastructure.GetControlId("SellRadio")); Assert.IsTrue(sellRadButton.IsSelected); break; } }
public void コントロール特定3() { WindowsAppExpander.LoadAssembly(_app, GetType().Assembly); WPFStandardControls_3_5.Injection(_app); AppVar main = _app.Type <Application>().Current.MainWindow; var userControl = main.LogicalTree().ByType("WpfApplication.DemoSimpleControl").Single(); var elements = _app.Type(GetType()).GetDemoSimpleControlElements(userControl); var textBlokX = new WPFTextBlock(elements.TextBlockXName); var textBlokMail = new WPFTextBlock(elements.TextBlockMail); var textBlokxLanguage = new WPFTextBlock(elements.TextBlockLanguage); var textBoxX = new WPFTextBox(elements.TextBoxXName); var textBoxMail = new WPFTextBox(elements.TextBoxMail); var comboBoxxLanguage = new WPFComboBox(elements.ComboBoxLanguage); var buttonOpen = new WPFButtonBase(elements.ButtonOpen); var button1 = new WPFButtonBase(elements.Button1); var buttonA = new WPFButtonBase(elements.ButtonA); var buttonCancel = new WPFButtonBase(elements.ButtonCancel); }
//validate if the screen has all the required controls and default values private void ValidateBuySellPanelControls(BuySellEnum buySell) { SelectBuySellTabPage(); TextBox symbolTextBox = Window.Get <TextBox>(TestDataInfrastructure.GetControlId("BuySellSymbolTextBox")); Assert.IsNotNull(symbolTextBox); RadioButton buyRadButton = Window.Get <RadioButton>(TestDataInfrastructure.GetControlId("BuyRadio")); Assert.IsNotNull(buyRadButton); RadioButton sellRadButton = Window.Get <RadioButton>(TestDataInfrastructure.GetControlId("SellRadio")); Assert.IsNotNull(sellRadButton); //check if Order type combobox is present WPFComboBox orderTypeComboBox = Window.Get <WPFComboBox>(TestDataInfrastructure.GetControlId("BuySellOrderTypeCombo")); Assert.IsNotNull(orderTypeComboBox); //check if shares textbox is present TextBox shareTextBox = Window.Get <TextBox>(TestDataInfrastructure.GetControlId("BuySellSharesTextBox")); Assert.IsNotNull(shareTextBox); //check if limit / stop price textbox is present TextBox limitStopPriceTextBox = Window.Get <TextBox>(TestDataInfrastructure.GetControlId("BuySellStopLimitPriceTextBox")); Assert.IsNotNull(limitStopPriceTextBox); WPFComboBox timeInForceComboBox = Window.Get <WPFComboBox>(TestDataInfrastructure.GetControlId("BuySellTimeInForceCombo")); Assert.IsNotNull(timeInForceComboBox); switch (buySell) { case BuySellEnum.Buy: Assert.IsTrue(buyRadButton.IsSelected); break; case BuySellEnum.Sell: Assert.IsTrue(sellRadButton.IsSelected); break; } //Button buyLastButton = window.Get<Button>(TestDataInfrastructure.GetControlId("BuySellBuyLastButton")); //Assert.IsNotNull(buyLastButton); //Button sellLastButton = window.Get<Button>(TestDataInfrastructure.GetControlId("BuySellSellLastButton")); //Assert.IsNotNull(sellLastButton); Button submitButton = Window.Get <Button>(TestDataInfrastructure.GetControlId("BuySellSubmitButton")); Assert.IsNotNull(submitButton); Button cancelButton = Window.Get <Button>(TestDataInfrastructure.GetControlId("BuySellCancelButton")); Assert.IsNotNull(cancelButton); //check if Submit All and Cancel All buttons are present Button submitAllButton = Window.Get <Button>(TestDataInfrastructure.GetControlId("BuySellSubmitAllButton")); Assert.IsNotNull(submitAllButton); Button cancelAllButton = Window.Get <Button>(TestDataInfrastructure.GetControlId("BuySellCancelAllButton")); Assert.IsNotNull(cancelAllButton); }
void Assert(string accessPath, WPFComboBox comboBox) => CaptureAdaptor.AddCode($"{accessPath}.SelectedIndex.Is({comboBox.SelectedIndex});");
public void コントロール特定() { // STEP1. // 複数のウィンドウ取得方法がある。 // 1.最前面のウィンドウを取得する。 var main = WindowControl.FromZTop(_app); // 2.アセンブリの正式名称を指定してウィンドウを取得する。 var main2 = WindowControl.IdentifyFromTypeFullName(_app, "WpfApplication.MainWindow"); // 3.ウィンドウタイトルを指定してウィンドウを取得する。 var main4 = WindowControl.IdentifyFromWindowText(_app, "Friendly Handson"); // 4.Application からアクセスしてメインウィンドウ=ターゲットのウィンドウを取得する。 var appWindow = _app.Type <Application>().Current.MainWindow; var main3 = new WindowControl(appWindow); // STEP2. // LogicalTree から対象のコントロールを取得する。 // ここで取得できるLogicalTree はFriendly 独自に列挙している。 var logical = main2.LogicalTree(); // .ByType<T>() で指定した型のコントロールを列挙する。 // .Single() で一つのコントロール用データに変換する。 AppVar tabCore = logical.ByType <TabControl>().Single(); var tabControl = new WPFTabControl(tabCore); tabControl.EmulateChangeSelectedIndex(1); tabControl.EmulateChangeSelectedIndex(0); // STEP3. // 独自コントロール(ユーザーコントロール)を取得する。 // 基本的にユーザーコントロールは1画面に一つなので.ByType() がおすすめ。 AppVar demoSimpleControlCore = logical.ByType("WpfApplication.DemoSimpleControl").Single(); // ここで取得するLogicalTree はDemoSimpleControl.xaml のルート要素から取得できるものとなる。 var innerLogicalTree = demoSimpleControlCore.LogicalTree(); // こんな方法でアクセスもできる。 var x = demoSimpleControlCore.Dynamic(); var fullNameCore = x.GetType().FullName; string fullName = fullNameCore; Console.WriteLine(fullName); // 動作は上と同じ。 //AppVar type = demoSimpleControlCore["GetType"](); //var fullNameCore = type["FullName"](); //string fullName = (string)fullNameCore.Core; // ユーザーコントロール配下のテキストボックスへアクセスする。 // x:Name をつけていればコントロール名でアクセス可能。 var textBox = new WPFTextBox(demoSimpleControlCore.Dynamic()._textBox); textBox.EmulateChangeText("abc"); // STEP4. // Window のDataContext(ViewModel)からコントロールを取得する。 var textBoxMail = new WPFTextBox(innerLogicalTree.ByBinding("Mail").Single()); textBoxMail.EmulateChangeText("[email protected]"); // Assertをかける。 Assert.AreEqual("[email protected]", textBoxMail.Text); // ComboBox を取得する。 var comboBoxLanguage = new WPFComboBox(innerLogicalTree.ByBinding("Language").Single()); comboBoxLanguage.EmulateChangeSelectedIndex(1); // GUIのテストシナリオ // https://github.com/Ishikawa-Tatsuya/WPFFriendlySampleDotNetConf2016 // シナリオテストをする場合、Driver は開発者、シナリオは開発者以外がかけるようになっている。 }