Skip to content

Commit

Permalink
test: Fix ios ElementTests (#796)
Browse files Browse the repository at this point in the history
* Fix ios ElementTests

* Use specfic text validation

* wait until elements count is 2

* try-catch to check element exists

* fix selector
  • Loading branch information
Dor-bl authored Jun 22, 2024
1 parent 53eceba commit 1132ec7
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions test/integration/IOS/ElementTest.cs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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]
Expand All @@ -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);
}
}

}
Expand Down

0 comments on commit 1132ec7

Please sign in to comment.