2022-07-31 00:57:21 +03:00
|
|
|
using System.Threading;
|
2022-12-19 00:52:33 +03:00
|
|
|
using NAPS2.App.Tests.Targets;
|
2022-07-31 01:03:52 +03:00
|
|
|
using NAPS2.App.Tests.Verification;
|
2023-03-25 22:57:08 +03:00
|
|
|
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
|
|
|
|
{
|
2022-12-26 00:16:13 +03:00
|
|
|
[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");
|
2024-08-11 05:09:29 +03:00
|
|
|
WaitFor(() => HasElementWithName("Always Ask"));
|
2023-03-25 22:57:08 +03:00
|
|
|
var deviceName = AppTestHelper.GetDeviceName(Driver.Wia);
|
2024-08-11 05:09:29 +03:00
|
|
|
// WIA driver is selected by default, so we just click the device
|
2023-03-25 22:57:08 +03:00
|
|
|
if (!string.IsNullOrEmpty(deviceName)) ClickAtName(deviceName);
|
2024-08-11 05:09:29 +03:00
|
|
|
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
|
|
|
|
2022-12-26 00:16:13 +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");
|
2024-08-11 05:09:29 +03:00
|
|
|
WaitFor(() => HasElementWithName("Always Ask"));
|
2023-03-25 22:57:08 +03:00
|
|
|
var deviceName = AppTestHelper.GetDeviceName(Driver.Twain);
|
2024-08-11 05:09:29 +03:00
|
|
|
ClickAtName("TWAIN Driver");
|
|
|
|
Thread.Sleep(100);
|
|
|
|
WaitFor(() => HasElementWithName("Always Ask"));
|
2023-03-25 22:57:08 +03:00
|
|
|
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
|
|
|
}
|