Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demo/ShopDesk.Core/AppText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public static class AppText

public static string Total(decimal amount) => "Total: " + Money.Format(amount);

public static string Exported(string path) => $"Cart exported to {path}";

public static string OrderPlaced(OrderResult order) => $"Order {order.OrderId} placed. Total: {Money.Format(order.Total)}";
}
2 changes: 1 addition & 1 deletion demo/ShopDesk.WinForms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void Export()
if (dialog.ShowDialog(this) == DialogResult.OK)
{
File.WriteAllText(dialog.FileName, Services.Cart.ToCsv());
status.Text = "Cart exported";
status.Text = AppText.Exported(dialog.FileName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion demo/ShopDesk.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void OnExport(object sender, RoutedEventArgs e)
if (dialog.ShowDialog(this) == true)
{
File.WriteAllText(dialog.FileName, Services.Cart.ToCsv());
StatusText.Text = "Cart exported";
StatusText.Text = AppText.Exported(dialog.FileName);
}
}

Expand Down
1 change: 1 addition & 0 deletions docs/windows-and-locators.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ there are no stale references. Every action is a report step.
|---|---|
| `Click()`, `DoubleClick()`, `RightClick()` | `Ui:ClickMode`: `Auto` (Invoke for WPF/XAML, mouse for WinForms/Win32), `Invoke`, `Mouse` |
| `Type(text)`, `Clear()` | through UI Automation when the field accepts it, otherwise typed. Password fields are masked in the report. |
| `TypeKeys(text)` | always typed on the keyboard, for controls that ignore values set through UI Automation (file dialogs) |
| `Check()`, `Uncheck()`, `SetChecked(bool)` | toggle pattern; only toggles when needed |
| `Select(item)` / `Select()` | an item of a combo box or list (expands and collapses as needed) / this element itself |
| `OpenMenu("File", "Export cart...")` | menu bars, including WinForms drop-downs that open as separate popup windows |
Expand Down
2 changes: 1 addition & 1 deletion examples/Taf.Desktop.Examples/Tests/MenuAndDialogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void ExportWritesTheCartAsCsv()
var main = On<MainWindow>();
main.StartExport();
On<FileDialog>().Choose(file);
main.WaitStatus("Cart exported");
Verify.Equal(main.WaitStatus("Cart exported"), $"Cart exported to {file}", "Status bar");

File.ReadAllLines(file).Should().Equal("Product,Quantity,Amount", "Canvas Backpack,2,59.98");
}
Expand Down
8 changes: 4 additions & 4 deletions examples/Taf.Desktop.Examples/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public MainWindow StartSearch(string text)
return this;
}

/// <summary>Waits until the status bar shows <paramref name="text"/> (the app finished an action).</summary>
public MainWindow WaitStatus(string text)
/// <summary>Waits until the status bar starts with <paramref name="prefix"/> (the app finished an action).</summary>
public string WaitStatus(string prefix)
{
status.WaitText(text);
return this;
status.WaitUntil(s => s.Text.StartsWith(prefix, StringComparison.Ordinal), $"starts with '{prefix}'");
return Status;
}

public MainWindow WaitUntilLoaded()
Expand Down
3 changes: 2 additions & 1 deletion src/Taf.Desktop.Core/Ui/Dialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void Choose(string path) => Step.Run($"Choose '{path}' in {Name} ('{Title
{
fileName = Element("fileName", Locator.ById("1148", ControlType.Edit)); // open dialog
}
fileName.Type(path);
// Typed, not set: the dialog keeps its own file name and may ignore text set through UI Automation.
fileName.TypeKeys(path);
fileName.Press(VirtualKeyShort.ENTER);
WaitClosed();
});
Expand Down
6 changes: 6 additions & 0 deletions src/Taf.Desktop.Core/Ui/UiElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ private static bool TrySetValue(IUiNode node, string text)
}
}

/// <summary>
/// Replaces the content by typing on the keyboard, like a user. For controls that ignore values set through UI
/// Automation (the file name box of Windows file dialogs).
/// </summary>
public void TypeKeys(string text) => Step.Run($"Type '{text}' into {Name} (keyboard)", () => WaitEnabled().TypeText(text));

public void Clear() => Step.Run($"Clear {Name}", () =>
{
var node = WaitEnabled();
Expand Down
Loading