Skip to content

Commit 492d0da

Browse files
authored
test: Add WaitTests for WebDriverWait (#555)
1 parent 83c7f4d commit 492d0da

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Appium.Net.Integration.Tests.helpers;
2+
using NUnit.Framework;
3+
using OpenQA.Selenium;
4+
using OpenQA.Selenium.Appium;
5+
using OpenQA.Selenium.Appium.Android;
6+
using OpenQA.Selenium.Support.UI;
7+
using System;
8+
using System.Diagnostics;
9+
10+
namespace Appium.Net.Integration.Tests.Android
11+
{
12+
public class WaitTests
13+
{
14+
private AndroidDriver _driver;
15+
private WebDriverWait _waitDriver;
16+
private TimeSpan _driverTimeOut = TimeSpan.FromSeconds(5);
17+
18+
[OneTimeSetUp]
19+
public void BeforeAll()
20+
{
21+
var capabilities = Env.ServerIsRemote()
22+
? Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos"))
23+
: Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos"));
24+
var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;
25+
_driver = new AndroidDriver(serverUri, capabilities, Env.InitTimeoutSec);
26+
}
27+
28+
[SetUp]
29+
public void SetUp()
30+
{
31+
_driver.StartActivity("io.appium.android.apis", ".ApiDemos");
32+
_waitDriver = new WebDriverWait(_driver, _driverTimeOut);
33+
_waitDriver.IgnoreExceptionTypes(typeof(NoSuchElementException));
34+
}
35+
36+
[Test]
37+
public void WebDriverWaitElementNotFoundTestCase()
38+
{
39+
try
40+
{
41+
var text = _waitDriver.Until(drv =>
42+
{
43+
return drv.FindElement(MobileBy.Id("Storage"));
44+
});
45+
}
46+
catch (Exception wx)
47+
{
48+
var excpetionType = wx.GetType();
49+
Assert.AreEqual(excpetionType, typeof(WebDriverTimeoutException));
50+
}
51+
}
52+
53+
[Test]
54+
public void WebDriverWaitIsWaitingTestCase()
55+
{
56+
Stopwatch stopWatch = new Stopwatch();
57+
stopWatch.Start();
58+
59+
try
60+
{
61+
var text = _waitDriver.Until(drv =>
62+
{
63+
return drv.FindElement(MobileBy.Id("Storage"));
64+
});
65+
}
66+
catch (Exception)
67+
{
68+
stopWatch.Stop();
69+
TimeSpan ts = stopWatch.Elapsed;
70+
Assert.AreEqual(ts.Seconds, _driverTimeOut.Seconds);
71+
}
72+
}
73+
74+
[OneTimeTearDown]
75+
public void AfterAll()
76+
{
77+
if (_driver != null)
78+
{
79+
_driver.CloseApp();
80+
_driver?.Quit();
81+
}
82+
if (!Env.ServerIsRemote())
83+
{
84+
AppiumServers.StopLocalService();
85+
}
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)