Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions test/integration/Android/WaitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Appium.Net.Integration.Tests.helpers;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Support.UI;
using System;
using System.Diagnostics;

namespace Appium.Net.Integration.Tests.Android
{
public class WaitTests
{
private AndroidDriver _driver;
private WebDriverWait _waitDriver;
private TimeSpan _driverTimeOut = TimeSpan.FromSeconds(5);

[OneTimeSetUp]
public void BeforeAll()
{
var capabilities = Env.ServerIsRemote()
? Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos"))
: Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos"));
var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;
_driver = new AndroidDriver(serverUri, capabilities, Env.InitTimeoutSec);
}

[SetUp]
public void SetUp()
{
_driver.StartActivity("io.appium.android.apis", ".ApiDemos");
_waitDriver = new WebDriverWait(_driver, _driverTimeOut);
_waitDriver.IgnoreExceptionTypes(typeof(NoSuchElementException));
}

[Test]
public void WebDriverWaitElementNotFoundTestCase()
{
try
{
var text = _waitDriver.Until(drv =>
{
return drv.FindElement(MobileBy.Id("Storage"));
});
}
catch (Exception wx)
{
var excpetionType = wx.GetType();
Assert.AreEqual(excpetionType, typeof(WebDriverTimeoutException));
}
}

[Test]
public void WebDriverWaitIsWaitingTestCase()
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();

try
{
var text = _waitDriver.Until(drv =>
{
return drv.FindElement(MobileBy.Id("Storage"));
});
}
catch (Exception)
{
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Assert.AreEqual(ts.Seconds, _driverTimeOut.Seconds);
}
}

[OneTimeTearDown]
public void AfterAll()
{
if (_driver != null)
{
_driver.CloseApp();
_driver?.Quit();
}
if (!Env.ServerIsRemote())
{
AppiumServers.StopLocalService();
}
}
}
}