From 1132ec765e7dac514230cff0618ffdc31ee59ad9 Mon Sep 17 00:00:00 2001 From: Dor Blayzer <59066376+Dor-bl@users.noreply.github.com> Date: Sat, 22 Jun 2024 07:54:07 +0300 Subject: [PATCH] test: Fix ios ElementTests (#796) * Fix ios ElementTests * Use specfic text validation * wait until elements count is 2 * try-catch to check element exists * fix selector --- test/integration/IOS/ElementTest.cs | 33 ++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/test/integration/IOS/ElementTest.cs b/test/integration/IOS/ElementTest.cs index 4f598cd3..eb3f1e1a 100644 --- a/test/integration/IOS/ElementTest.cs +++ b/test/integration/IOS/ElementTest.cs @@ -1,14 +1,17 @@ -using Appium.Net.Integration.Tests.helpers; +using System; +using Appium.Net.Integration.Tests.helpers; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.iOS; +using OpenQA.Selenium.Support.UI; namespace Appium.Net.Integration.Tests.IOS { - class ElementTest + class ElementTests { private AppiumDriver _driver; + private WebDriverWait _driverWait; [OneTimeSetUp] public void BeforeAll() @@ -17,6 +20,7 @@ public void BeforeAll() var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; _driver = new IOSDriver(serverUri, capabilities, Env.InitTimeoutSec); _driver.Manage().Timeouts().ImplicitWait = Env.ImplicitTimeoutSec; + _driverWait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5)); } [OneTimeTearDown] @@ -35,20 +39,29 @@ public void FindByAccessibilityIdTest() By byAccessibilityId = new ByAccessibilityId("ComputeSumButton"); Assert.Multiple(() => { - Assert.That(Is.Not.EqualTo(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byAccessibilityId).Text), null); - Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byAccessibilityId), Is.Not.Empty); + Assert.That(_driver.FindElement(MobileBy.ClassName("UIAWindow")).FindElement(byAccessibilityId).Text, Is.EqualTo("Compute Sum")); + Assert.That(_driver.FindElement(MobileBy.ClassName("UIAWindow")).FindElements(byAccessibilityId), Is.Not.Empty); }); } [Test] - public void FindByByIosUiAutomationTest() + public void FindElementsByClassNameTest() { - By byIosUiAutomation = new ByIosUIAutomation(".elements().withName(\"Answer\")"); - Assert.Multiple(() => + By byClassName = new ByClassName("XCUIElementTypeTextField"); + Assert.That(_driverWait.Until(_driver => _driver.FindElements(byClassName).Count == 2), Is.True); + } + + [Test] + public void FindElementMobileByClassNameTest() + { + try { - Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byIosUiAutomation).Text, Is.Not.Null); - Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byIosUiAutomation), Is.Not.Empty); - }); + var switchElement = _driver.FindElement(MobileBy.ClassName("XCUIElementTypeSwitch")); + } + catch (NoSuchElementException ex) + { + Assert.Fail("Element not found, exception: " + ex.Message); + } } }