Skip to content

Commit

Permalink
Add push/pull file commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Abalov authored and Nick Abalov committed Mar 4, 2016
1 parent efb0b81 commit 5df6a7b
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Winium/TestApp.Test/py-functional/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
import pytest
from selenium.webdriver import Remote
from appium.webdriver import Remote
from selenium.webdriver.support.wait import WebDriverWait
import config

Expand Down
8 changes: 8 additions & 0 deletions Winium/TestApp.Test/py-functional/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding: utf-8
from time import sleep
import base64

import pytest
from selenium.common.exceptions import NoSuchElementException, NoAlertPresentException, WebDriverException
Expand Down Expand Up @@ -171,6 +172,13 @@ def test_is_displayed(self):
assert self.driver.find_element_by_name('June').is_displayed()
assert not self.driver.find_element_by_name('August').is_displayed()

def test_file_ops(self):
with open(__file__) as f:
encoded = base64.b64encode(f.read())
self.driver.push_file(r"test\sample.dat", encoded)
data = self.driver.pull_file(r"test\sample.dat")
assert encoded == data


class UsesSecondTab(WuaTestCase):
@pytest.fixture
Expand Down
10 changes: 8 additions & 2 deletions Winium/Winium.Mobile.Connectivity/Deployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ public void Launch()

public void ReceiveFile(string isoStoreRoot, string sourceDeviceFilePath, string targetDesktopFilePath)
{
this.RemoteApplication.GetIsolatedStore(isoStoreRoot)
.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath, true);
var isolatedStore = this.RemoteApplication.GetIsolatedStore(isoStoreRoot);
isolatedStore.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath, true);
}

public void SendFile(string isoStoreRoot, string sourceDesktopFilePath, string targetDeviceFilePath)
{
var isolatedStore = this.RemoteApplication.GetIsolatedStore(isoStoreRoot);
isolatedStore.SendFile(sourceDesktopFilePath, targetDeviceFilePath, true);
}

public void SendFiles(List<KeyValuePair<string, string>> files)
Expand Down
2 changes: 2 additions & 0 deletions Winium/Winium.Mobile.Connectivity/IDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface IDeployer

void SendFiles(List<KeyValuePair<string, string>> files);

void SendFile(string isoStoreRoot, string sourceDesktopFilePath, string targetDeviceFilePath);

void Terminate();

void Uninstall();
Expand Down
4 changes: 4 additions & 0 deletions Winium/Winium.StoreApps.Common/DriverCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ public static class DriverCommand

public static readonly string CloseApp = "closeApp";

public static readonly string PullFile = "pullFile";

public static readonly string PushFile = "pushFile";

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Winium.StoreApps.Driver.CommandExecutors
{
using System;
using System.IO;

using Winium.StoreApps.Common;
using Winium.StoreApps.Driver.Automator;

internal class PullFileExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
var path = Automator.GetValue<string>(this.ExecutedCommand.Parameters, "path");

var localPath = Path.GetTempFileName();

try
{
this.Automator.Deployer.ReceiveFile("Local", path, localPath);

var bytes = File.ReadAllBytes(localPath);
var data = Convert.ToBase64String(bytes);
return this.JsonResponse(ResponseStatus.Success, data);
}
finally
{
File.Delete(localPath);
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Winium.StoreApps.Driver.CommandExecutors
{
using System;
using System.IO;

using Winium.StoreApps.Driver.Automator;

internal class PushFileExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
var path = Automator.GetValue<string>(this.ExecutedCommand.Parameters, "path");
var data = Automator.GetValue<string>(this.ExecutedCommand.Parameters, "data");

var localPath = Path.GetTempFileName();

try
{
File.WriteAllBytes(localPath, Convert.FromBase64String(data));
this.Automator.Deployer.SendFile("Local", localPath, path);
}
finally
{
File.Delete(localPath);
}

return this.JsonResponse();
}

#endregion
}
}
18 changes: 15 additions & 3 deletions Winium/Winium.StoreApps.Driver/UriDispatchTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,25 @@ private void InitializeSeleniumCommandDictionary()

private void InitializeWiniumCommandDictionary()
{
this.commandDictionary.Add(DriverCommand.GetElementRect, new CommandInfo("GET", "/session/{sessionId}/element/{id}/rect"));
this.commandDictionary.Add(
DriverCommand.GetElementRect,
new CommandInfo("GET", "/session/{sessionId}/element/{id}/rect"));
}

private void InitializeAppiumCommandDictionary()
{
this.commandDictionary.Add(DriverCommand.LaunchApp, new CommandInfo("POST", "/session/{sessionId}/appium/app/launch"));
this.commandDictionary.Add(DriverCommand.CloseApp, new CommandInfo("POST", "/session/{sessionId}/appium/app/close"));
this.commandDictionary.Add(
DriverCommand.LaunchApp,
new CommandInfo("POST", "/session/{sessionId}/appium/app/launch"));
this.commandDictionary.Add(
DriverCommand.CloseApp,
new CommandInfo("POST", "/session/{sessionId}/appium/app/close"));
this.commandDictionary.Add(
DriverCommand.PullFile,
new CommandInfo("POST", "/session/{sessionId}/appium/device/pull_file"));
this.commandDictionary.Add(
DriverCommand.PushFile,
new CommandInfo("POST", "/session/{sessionId}/appium/device/push_file"));
}

#endregion
Expand Down
2 changes: 2 additions & 0 deletions Winium/Winium.StoreApps.Driver/Winium.StoreApps.Driver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<Compile Include="CommandExecutors\GetElementAttributeExecutor.cs" />
<Compile Include="CommandExecutors\CloseAppExecutor.cs" />
<Compile Include="CommandExecutors\LaunchAppExecutor.cs" />
<Compile Include="CommandExecutors\PullFileExecutor.cs" />
<Compile Include="CommandExecutors\PushFileExecutor.cs" />
<Compile Include="CommandExecutors\SetOrientationExecutor.cs" />
<Compile Include="CommandExecutors\SubmitElementExecutor.cs" />
<Compile Include="CommandExecutorDispatchTable.cs" />
Expand Down
Loading

0 comments on commit 5df6a7b

Please sign in to comment.