Skip to content

Commit 1132ec7

Browse files
authored
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
1 parent 53eceba commit 1132ec7

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

test/integration/IOS/ElementTest.cs

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
using Appium.Net.Integration.Tests.helpers;
1+
using System;
2+
using Appium.Net.Integration.Tests.helpers;
23
using NUnit.Framework;
34
using OpenQA.Selenium;
45
using OpenQA.Selenium.Appium;
56
using OpenQA.Selenium.Appium.iOS;
7+
using OpenQA.Selenium.Support.UI;
68

79
namespace Appium.Net.Integration.Tests.IOS
810
{
9-
class ElementTest
11+
class ElementTests
1012
{
1113
private AppiumDriver _driver;
14+
private WebDriverWait _driverWait;
1215

1316
[OneTimeSetUp]
1417
public void BeforeAll()
@@ -17,6 +20,7 @@ public void BeforeAll()
1720
var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;
1821
_driver = new IOSDriver(serverUri, capabilities, Env.InitTimeoutSec);
1922
_driver.Manage().Timeouts().ImplicitWait = Env.ImplicitTimeoutSec;
23+
_driverWait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
2024
}
2125

2226
[OneTimeTearDown]
@@ -35,20 +39,29 @@ public void FindByAccessibilityIdTest()
3539
By byAccessibilityId = new ByAccessibilityId("ComputeSumButton");
3640
Assert.Multiple(() =>
3741
{
38-
Assert.That(Is.Not.EqualTo(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byAccessibilityId).Text), null);
39-
Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byAccessibilityId), Is.Not.Empty);
42+
Assert.That(_driver.FindElement(MobileBy.ClassName("UIAWindow")).FindElement(byAccessibilityId).Text, Is.EqualTo("Compute Sum"));
43+
Assert.That(_driver.FindElement(MobileBy.ClassName("UIAWindow")).FindElements(byAccessibilityId), Is.Not.Empty);
4044
});
4145
}
4246

4347
[Test]
44-
public void FindByByIosUiAutomationTest()
48+
public void FindElementsByClassNameTest()
4549
{
46-
By byIosUiAutomation = new ByIosUIAutomation(".elements().withName(\"Answer\")");
47-
Assert.Multiple(() =>
50+
By byClassName = new ByClassName("XCUIElementTypeTextField");
51+
Assert.That(_driverWait.Until(_driver => _driver.FindElements(byClassName).Count == 2), Is.True);
52+
}
53+
54+
[Test]
55+
public void FindElementMobileByClassNameTest()
56+
{
57+
try
4858
{
49-
Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElement(byIosUiAutomation).Text, Is.Not.Null);
50-
Assert.That(_driver.FindElements(MobileBy.ClassName("UIAWindow"))[1].FindElements(byIosUiAutomation), Is.Not.Empty);
51-
});
59+
var switchElement = _driver.FindElement(MobileBy.ClassName("XCUIElementTypeSwitch"));
60+
}
61+
catch (NoSuchElementException ex)
62+
{
63+
Assert.Fail("Element not found, exception: " + ex.Message);
64+
}
5265
}
5366

5467
}

0 commit comments

Comments
 (0)