naps2/NAPS2.App.Tests/Appium/ScanAndSaveTests.cs

83 lines
3.4 KiB
C#
Raw Normal View History

2022-07-31 00:57:21 +03:00
using System.Threading;
2022-12-19 00:52:33 +03:00
using NAPS2.App.Tests.Targets;
using NAPS2.App.Tests.Verification;
using NAPS2.Scan;
2022-07-31 00:57:21 +03:00
using NAPS2.Sdk.Tests.Asserts;
using Xunit;
namespace NAPS2.App.Tests.Appium;
2022-12-21 08:24:16 +03:00
#pragma warning disable CS0162
2022-07-31 00:57:21 +03:00
[Collection("appium")]
public class ScanAndSaveTests : AppiumTests
{
[VerifyTheory(AllowDebug = true, WindowsAppium = true)]
2022-12-19 00:52:33 +03:00
[ClassData(typeof(AppiumTestData))]
public void ScanWiaSavePdf(IAppTestTarget target)
2022-07-31 00:57:21 +03:00
{
2022-12-19 00:52:33 +03:00
Init(target);
2022-07-31 00:57:21 +03:00
// Clicking Scan without a profile opens the profile settings window
ClickAtName("Scan");
ClickAtName("Choose device");
WaitFor(() => HasElementWithName("Always Ask"));
var deviceName = AppTestHelper.GetDeviceName(Driver.Wia);
// WIA driver is selected by default, so we just click the device
if (!string.IsNullOrEmpty(deviceName)) ClickAtName(deviceName);
ClickAt(_session.FindElementByName("Select"));
WaitFor(() => !HasElementWithName("Select"));
2022-07-31 00:57:21 +03:00
// Click OK in the profile settings window
ClickAtName("OK");
2023-07-09 04:26:36 +03:00
WaitFor(() => HasElementWithName("Cancel"));
2022-07-31 00:57:21 +03:00
// Wait for scanning to finish
2023-07-09 04:26:36 +03:00
WaitFor(() => !HasElementWithName("Cancel"), 30_000);
2022-07-31 00:57:21 +03:00
ResetMainWindow();
// Save "test.pdf" in the default location (which will be the test data path as NAPS2 knows we're in a test)^
ClickAtName("Save PDF");
ResetMainWindow();
2023-07-09 04:26:36 +03:00
var fileTextBox = WaitFor(() => _session.FindElementsByName("File name:").Last());
2022-07-31 00:57:21 +03:00
ClickAt(fileTextBox);
fileTextBox.SendKeys("test.pdf");
ClickAtName("Save");
// Wait for the save to finish, it should be almost instant
2023-03-20 05:27:23 +03:00
Thread.Sleep(1000);
2022-07-31 00:57:21 +03:00
PdfAsserts.AssertPageCount(1, Path.Combine(FolderPath, "test.pdf"));
AppTestHelper.AssertNoErrorLog(FolderPath);
}
2022-07-31 02:05:47 +03:00
[VerifyTheory(AllowDebug = true, WindowsAppium = true)]
2022-12-19 00:52:33 +03:00
[ClassData(typeof(AppiumTestData))]
public void ScanTwainSaveImage(IAppTestTarget target)
2022-07-31 02:05:47 +03:00
{
2022-12-19 00:52:33 +03:00
Init(target);
2022-07-31 02:05:47 +03:00
// Clicking Scan without a profile opens the profile settings window
ClickAtName("Scan");
ClickAtName("Choose device");
WaitFor(() => HasElementWithName("Always Ask"));
var deviceName = AppTestHelper.GetDeviceName(Driver.Twain);
ClickAtName("TWAIN Driver");
Thread.Sleep(100);
WaitFor(() => HasElementWithName("Always Ask"));
if (!string.IsNullOrEmpty(deviceName)) ClickAtName(deviceName);
2022-07-31 02:05:47 +03:00
ClickAtName("Select");
2023-07-09 04:26:36 +03:00
WaitFor(() => !HasElementWithName("Select"));
2022-07-31 02:05:47 +03:00
// Click OK in the profile settings window
ClickAtName("OK");
2023-07-09 04:26:36 +03:00
WaitFor(() => HasElementWithName("Cancel"));
2022-07-31 02:05:47 +03:00
// Wait for scanning to finish
2023-07-09 04:26:36 +03:00
WaitFor(() => !HasElementWithName("Cancel"), 30_000);
2022-07-31 02:05:47 +03:00
ResetMainWindow();
// Save "test.pdf" in the default location (which will be the test data path as NAPS2 knows we're in a test)^
ClickAtName("Save Images");
ResetMainWindow();
2023-07-09 04:26:36 +03:00
var fileTextBox = WaitFor(() => _session.FindElementsByName("File name:").Last());
2022-07-31 02:05:47 +03:00
ClickAt(fileTextBox);
fileTextBox.SendKeys("test.jpg");
ClickAtName("Save");
// Wait for the save to finish, it should be almost instant
2023-03-20 05:27:23 +03:00
Thread.Sleep(1000);
2022-07-31 02:05:47 +03:00
ImageAsserts.Inches(Path.Combine(FolderPath, "test.jpg"), 8.5, 11);
AppTestHelper.AssertNoErrorLog(FolderPath);
}
2022-07-31 00:57:21 +03:00
}