Skip to content

Commit 999ed48

Browse files
authored
test: Add FiltersTests class with NUnit tests for Filters.FirstWithName (#902)
* Add FiltersTests class with NUnit tests for Filters.FirstWithName Introduced a new test class `FiltersTests` in the `Appium.Net.Integration.Tests.helpers` namespace. The class is decorated with the `[TestFixture]` attribute and includes the following methods: - `BeforeAll()`: Initializes the `AndroidDriver` and sets the implicit wait timeout. - `SetUp()`: Starts the "ApiDemos" activity before each test. - `FirstWithName_ReturnsCorrectElement()`: Verifies that `Filters.FirstWithName` returns the correct element. - `AfterAll()`: Quits the `AndroidDriver` and stops the local Appium service if the server is not remote. Necessary namespaces for NUnit, Selenium, and Appium are imported. * Refactor namespaces and add using directive Added `using` directive for `Appium.Net.Integration.Tests.helpers`. Changed namespace from `Appium.Net.Integration.Tests.helpers` to `Appium.Net.Integration.Tests.Android` for better organization. * Fix typo in variable name in FirstWithName_ReturnsCorrectElement * Simplify initialization of `capabilities` in `BeforeAll` * Remove SetUp method that started ApiDemos activity
1 parent 5e8a09c commit 999ed48

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//Licensed under the Apache License, Version 2.0 (the "License");
2+
//you may not use this file except in compliance with the License.
3+
//See the NOTICE file distributed with this work for additional
4+
//information regarding copyright ownership.
5+
//You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
//Unless required by applicable law or agreed to in writing, software
10+
//distributed under the License is distributed on an "AS IS" BASIS,
11+
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//See the License for the specific language governing permissions and
13+
//limitations under the License.
14+
15+
using System.Collections.Generic;
16+
using NUnit.Framework;
17+
using OpenQA.Selenium.Appium.Android;
18+
using OpenQA.Selenium.Appium;
19+
using Appium.Net.Integration.Tests.helpers;
20+
21+
namespace Appium.Net.Integration.Tests.Android
22+
{
23+
[TestFixture]
24+
public class FiltersTests
25+
{
26+
private AndroidDriver _driver;
27+
28+
[OneTimeSetUp]
29+
public void BeforeAll()
30+
{
31+
var capabilities = Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos"));
32+
var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;
33+
_driver = new AndroidDriver(serverUri, capabilities, Env.InitTimeoutSec);
34+
_driver.Manage().Timeouts().ImplicitWait = Env.ImplicitTimeoutSec;
35+
}
36+
37+
[Test]
38+
public void FirstWithName_ReturnsCorrectElement()
39+
{
40+
var viewsElement = _driver.FindElement(MobileBy.AccessibilityId("Views"));
41+
42+
var textElement = _driver.FindElement(MobileBy.AccessibilityId("Text"));
43+
44+
var elements = new List<AppiumElement> { viewsElement, textElement };
45+
46+
var result = Filters.FirstWithName(elements, "Text");
47+
48+
Assert.That(result, Is.EqualTo(textElement));
49+
}
50+
51+
[OneTimeTearDown]
52+
public void AfterAll()
53+
{
54+
_driver?.Quit();
55+
if (!Env.ServerIsRemote())
56+
{
57+
AppiumServers.StopLocalService();
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)