-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
277 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>WinAppDriver.Infra</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Windows.Apps.Test" Version="1.0.181205002" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="System.Drawing.Common" Version="5.0.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
del /f /q /s bin\Release\netcoreapp3.1\win-x64 | ||
del /f /q /s bin\Release\net6.0\win-x64 | ||
dotnet publish -c Release -r win-x64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.Razor; | ||
using Newtonsoft.Json.Linq; | ||
using WinAppDriver.Infra; | ||
using WinAppDriver.Infra.Request; | ||
using WinAppDriver.Infra.Result; | ||
using Xunit; | ||
|
||
namespace WinAppDriver.IntegrationTest | ||
{ | ||
[Collection("Sequential")] | ||
public class DeviceTest: IDisposable | ||
{ | ||
public readonly string _tempDirectory; | ||
public readonly string _uniqueTempDirectory; | ||
|
||
public DeviceTest() | ||
{ | ||
_tempDirectory = Path.GetTempPath(); | ||
_uniqueTempDirectory = Path.Combine(_tempDirectory, Guid.NewGuid().ToString()); | ||
|
||
Directory.CreateDirectory(_uniqueTempDirectory); | ||
} | ||
|
||
[Theory] | ||
[InlineData("file.bin")] | ||
[InlineData("foo\\bar\\file.bin")] | ||
public async Task Test_PushFile_UploadFileToRemote(string partialFilePath) | ||
{ | ||
using (var client = new TestClientProvider().Client) | ||
{ | ||
var sessionId = await Helpers.CreateNewSession(client, AppIds.WinVer); | ||
sessionId.Should().NotBeNullOrEmpty(); | ||
|
||
try | ||
{ | ||
var fileContent = Guid.NewGuid().ToByteArray(); | ||
var filePath = Path.Combine(_uniqueTempDirectory, partialFilePath); | ||
|
||
var res = await Helpers.PostSessionMessage<object, PathFileReq>(client, sessionId, "appium/device/push_file", | ||
new PathFileReq() { data = Convert.ToBase64String(fileContent), path = filePath }); | ||
|
||
res.statusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
File.Exists(filePath).Should().BeTrue(); | ||
(await File.ReadAllBytesAsync(filePath)).Should().BeEquivalentTo(fileContent); | ||
} | ||
finally | ||
{ | ||
|
||
await Helpers.DeletSession(client, sessionId); | ||
} | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "content", "Invalid path: Null or whitespace")] // path empty | ||
[InlineData("C:\\file.bin", "", "Invalid file content: Null or whitespace")] // empty content | ||
[InlineData("C:\\file.bin", "???????", "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.")] // invalid content | ||
public async Task Test_PushFile_InvalidPayload(string filePath, string fileContent, string errorMessage) | ||
{ | ||
using (var client = new TestClientProvider().Client) | ||
{ | ||
var sessionId = await Helpers.CreateNewSession(client, AppIds.WinVer); | ||
sessionId.Should().NotBeNullOrEmpty(); | ||
|
||
try | ||
{ | ||
var res = await Helpers.PostSessionMessage<object, PathFileReq>(client, sessionId, "appium/device/push_file", | ||
new PathFileReq() { data = fileContent, path = filePath }); | ||
|
||
res.statusCode.Should().Be(HttpStatusCode.InternalServerError); | ||
res.value.Should().BeOfType<JObject>(); | ||
|
||
var resValue = (JObject)res.value; | ||
|
||
resValue.Value<string>("error").Should().BeEquivalentTo("UnknownError"); | ||
resValue.Value<string>("message").Should().BeEquivalentTo(errorMessage); | ||
} | ||
finally | ||
{ | ||
await Helpers.DeletSession(client, sessionId); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Test_PullFile_DownloadFileFromRemote() | ||
{ | ||
using (var client = new TestClientProvider().Client) | ||
{ | ||
var sessionId = await Helpers.CreateNewSession(client, AppIds.WinVer); | ||
sessionId.Should().NotBeNullOrEmpty(); | ||
|
||
try | ||
{ | ||
var fileContent = Guid.NewGuid().ToByteArray(); | ||
var filePath = Path.Combine(_uniqueTempDirectory, "file.bin"); | ||
File.WriteAllBytes(filePath, fileContent); | ||
|
||
var res = await Helpers.PostSessionMessage<object, PathFileReq>(client, sessionId, "appium/device/pull_file", | ||
new PathFileReq() { path = filePath }); | ||
|
||
res.statusCode.Should().Be(HttpStatusCode.OK); | ||
res.value.Should().BeEquivalentTo(Convert.ToBase64String(fileContent)); | ||
} | ||
finally | ||
{ | ||
|
||
await Helpers.DeletSession(client, sessionId); | ||
} | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "Invalid path: Null or whitespace")] // path empty | ||
[InlineData("C:\\file.bin", "The requested file doesn't exist.")] // file doesn't exist | ||
public async Task Test_PullFile_InvalidPayload(string filePath, string errorMessage) | ||
{ | ||
using (var client = new TestClientProvider().Client) | ||
{ | ||
var sessionId = await Helpers.CreateNewSession(client, AppIds.WinVer); | ||
sessionId.Should().NotBeNullOrEmpty(); | ||
|
||
try | ||
{ | ||
var res = await Helpers.PostSessionMessage<object, PathFileReq>(client, sessionId, "appium/device/pull_file", | ||
new PathFileReq() { path = filePath }); | ||
|
||
res.statusCode.Should().Be(HttpStatusCode.InternalServerError); | ||
res.value.Should().BeOfType<JObject>(); | ||
|
||
var resValue = (JObject)res.value; | ||
|
||
resValue.Value<string>("error").Should().BeEquivalentTo("UnknownError"); | ||
resValue.Value<string>("message").Should().BeEquivalentTo(errorMessage); | ||
} | ||
finally | ||
{ | ||
await Helpers.DeletSession(client, sessionId); | ||
} | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (Directory.Exists(_uniqueTempDirectory)) | ||
{ | ||
Directory.Delete(_uniqueTempDirectory, true); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
test/WinAppDriver.IntegrationTest/WinAppDriver.IntegrationTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.