mirror of
https://github.com/cyanfish/naps2.git
synced 2024-08-17 11:10:23 +03:00
Use a config file for appium test device names
This commit is contained in:
parent
f0cb9481b0
commit
b804a8a7d7
@ -1,6 +1,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using NAPS2.App.Tests.Targets;
|
||||
using NAPS2.Scan;
|
||||
using Xunit;
|
||||
|
||||
namespace NAPS2.App.Tests;
|
||||
@ -105,4 +106,19 @@ public static class AppTestHelper
|
||||
|
||||
public static string SolutionRoot =>
|
||||
Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", ".."));
|
||||
|
||||
public static string GetDeviceName(Driver driver)
|
||||
{
|
||||
var deviceFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".naps2", "devices");
|
||||
if (!File.Exists(deviceFileName)) return null;
|
||||
var driverStr = driver.ToString().ToLowerInvariant();
|
||||
foreach (var line in File.ReadLines(deviceFileName))
|
||||
{
|
||||
if (line.StartsWith(driverStr + "="))
|
||||
{
|
||||
return line.Trim().Substring(driverStr.Length + 1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System.Threading;
|
||||
using NAPS2.App.Tests.Targets;
|
||||
using NAPS2.App.Tests.Verification;
|
||||
using NAPS2.Scan;
|
||||
using NAPS2.Sdk.Tests.Asserts;
|
||||
using Xunit;
|
||||
|
||||
@ -10,9 +11,6 @@ namespace NAPS2.App.Tests.Appium;
|
||||
[Collection("appium")]
|
||||
public class ScanAndSaveTests : AppiumTests
|
||||
{
|
||||
private const string WIA_DEVICE_NAME = "";
|
||||
private const string TWAIN_DEVICE_NAME = "";
|
||||
|
||||
[VerifyTheory(AllowDebug = true, WindowsAppium = true)]
|
||||
[ClassData(typeof(AppiumTestData))]
|
||||
public void ScanWiaSavePdf(IAppTestTarget target)
|
||||
@ -23,7 +21,8 @@ public class ScanAndSaveTests : AppiumTests
|
||||
// WIA driver is selected by default, so we open the WIA device dialog
|
||||
ClickAtName("Choose device");
|
||||
Thread.Sleep(100);
|
||||
if (WIA_DEVICE_NAME != "") ClickAtName(WIA_DEVICE_NAME);
|
||||
var deviceName = AppTestHelper.GetDeviceName(Driver.Wia);
|
||||
if (!string.IsNullOrEmpty(deviceName)) ClickAtName(deviceName);
|
||||
// Click OK in the wia device dialog (selecting the first available device by default)
|
||||
// TODO: More consistent way to pick the right OK button
|
||||
ClickAt(_session.FindElementsByName("OK")[0]);
|
||||
@ -59,7 +58,8 @@ public class ScanAndSaveTests : AppiumTests
|
||||
// Open the TWAIN device dialog
|
||||
ClickAtName("Choose device");
|
||||
Thread.Sleep(100);
|
||||
if (TWAIN_DEVICE_NAME != "") ClickAtName(TWAIN_DEVICE_NAME);
|
||||
var deviceName = AppTestHelper.GetDeviceName(Driver.Twain);
|
||||
if (!string.IsNullOrEmpty(deviceName)) ClickAtName(deviceName);
|
||||
// Click Select in the twain device dialog (selecting the first available device by default)
|
||||
ClickAtName("Select");
|
||||
WaitUntilGone("Select", 1_000);
|
||||
|
Loading…
Reference in New Issue
Block a user