EmbeddingTests.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using Xunit;
  3. namespace Avalonia.IntegrationTests.Appium
  4. {
  5. [Collection("Default")]
  6. public class EmbeddingTests : TestBase
  7. {
  8. public EmbeddingTests(DefaultAppFixture fixture)
  9. : base(fixture, "Embedding")
  10. {
  11. }
  12. [PlatformFact(TestPlatforms.Windows, "Not yet working on macOS")]
  13. public void Can_Edit_Native_TextBox()
  14. {
  15. // Appium has different XPath syntax between Windows and macOS.
  16. var textBox = OperatingSystem.IsWindows() ?
  17. Session.FindElementByXPath($"//*[@AutomationId='NativeTextBox']//*[1]") :
  18. Session.FindElementByXPath($"//*[@identifier='NativeTextBox']//*[1]");
  19. Assert.Equal("Native text box", textBox.Text);
  20. textBox.SendKeys("Hello world!");
  21. // SendKeys behaves differently between Windows and macOS. On Windows it inserts at the start
  22. // of the text box, on macOS it replaces the text for some reason. Sigh.
  23. var expected = OperatingSystem.IsWindows() ?
  24. "Hello world!Native text box" :
  25. "Hello world!";
  26. Assert.Equal(expected, textBox.Text);
  27. }
  28. [PlatformFact(TestPlatforms.Windows, "Not yet working on macOS")]
  29. public void Can_Edit_Native_TextBox_In_Popup()
  30. {
  31. var checkBox = Session.FindElementByAccessibilityId("EmbeddingPopupOpenCheckBox");
  32. checkBox.Click();
  33. try
  34. {
  35. // Appium has different XPath syntax between Windows and macOS.
  36. var textBox = OperatingSystem.IsWindows() ?
  37. Session.FindElementByXPath($"//*[@AutomationId='NativeTextBoxInPopup']//*[1]") :
  38. Session.FindElementByXPath($"//*[@identifier='NativeTextBoxInPopup']//*[1]");
  39. Assert.Equal("Native text box", textBox.Text);
  40. textBox.SendKeys("Hello world!");
  41. // SendKeys behaves differently between Windows and macOS. On Windows it inserts at the start
  42. // of the text box, on macOS it replaces the text for some reason. Sigh.
  43. var expected = OperatingSystem.IsWindows() ?
  44. "Hello world!Native text box" :
  45. "Hello world!";
  46. Assert.Equal(expected, textBox.Text);
  47. }
  48. finally
  49. {
  50. checkBox.Click();
  51. }
  52. }
  53. }
  54. }