Skip to content

Commit

Permalink
fix input functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shai1712 committed Jan 29, 2025
1 parent 30d8954 commit 7dc495d
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@
<Label Style="{StaticResource $LabelStyle}" Content="Script:"/>
<Actions:UCValueExpression x:Name="xAppPackageVE2" VerticalAlignment="Top" Width="400"/>
</StackPanel>

<StackPanel x:Name="xPushToDevicePnl" HorizontalAlignment="Left" Orientation="Horizontal" DockPanel.Dock="Top" Margin="5,10,0,0" Visibility="Collapsed">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" DockPanel.Dock="Top">
<Label Style="{StaticResource $LabelStyle}" Content="Choose File:"/>
<Actions:UCValueExpression x:Name="xPhotoSumilationEV" HorizontalAlignment="Left" VerticalAlignment="Center" Width="600" />
</StackPanel>
</StackPanel>
<StackPanel x:Name="xPullFromDevicePnl" HorizontalAlignment="Left" Orientation="Horizontal" DockPanel.Dock="Top" Margin="5,10,0,0" Visibility="Collapsed">
<Label Style="{StaticResource $LabelStyle}" Content="Enter File Name From Device:" Margin="0,5,0,0"/>
<Actions:UCValueExpression x:Name="xAppPackageVE3" VerticalAlignment="Top" Margin="5,8,30,8" Width="200"/>
<Label Style="{StaticResource $LabelStyle}" Content="Choose Folder:" Margin="0,5,0,0"/>
<Actions:UCValueExpression x:Name="xPhotoSumilationVE2" Width="600" />
</StackPanel>
<StackPanel x:Name="xSetClipboardTextPnl" HorizontalAlignment="Left" Orientation="Horizontal" DockPanel.Dock="Top" Margin="5,10,0,0" Visibility="Collapsed">
<Label Style="{StaticResource $LabelStyle}" Content="Set value to Clipboard Text:" Margin="0,5,0,0"/>
<Actions:UCValueExpression x:Name="xAppPackageVE4" VerticalAlignment="Top" Margin="5,7,30,8" Width="200"/>

</StackPanel>
</DockPanel>
</Page>

Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ private void BindControls()

xAppPackageDeepLinkVE.Init(Context.GetAsContext(mAct.Context), mAct.ActionAppPackage, nameof(ActInputValue.Value));

xURLNameTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.URLName, nameof(ActInputValue.Value));
xURLNameTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.URLName, nameof(ActInputValue.Value));

xAppPackageVE2.Init(Context.GetAsContext(mAct.Context), mAct.Script, nameof(ActInputValue.Value));
xPhotoSumilationVE2.Init(Context.GetAsContext(mAct.Context), mAct.LocalFile, nameof(ActInputValue.Value), true, true, UCValueExpression.eBrowserType.Folder, "*");

xPhotoSumilationEV.Init(Context.GetAsContext(mAct.Context), mAct.LocalFile, nameof(ActMobileDevice.Value), true, true, UCValueExpression.eBrowserType.File, "*");

xAppPackageVE3.Init(Context.GetAsContext(mAct.Context), mAct.ActionInput, nameof(ActInputValue.Value));
xAppPackageVE2.Init(Context.GetAsContext(mAct.Context), mAct.ActionInput, nameof(ActInputValue.Value));
xAppPackageVE4.Init(Context.GetAsContext(mAct.Context), mAct.ActionInput, nameof(ActInputValue.Value));

xPhotoSumilationVE.Init(Context.GetAsContext(mAct.Context), mAct.PathRecording, nameof(ActInputValue.Value), true, true, UCValueExpression.eBrowserType.Folder, "*");

Expand Down Expand Up @@ -221,6 +227,9 @@ private void SetControlsView()
xDeepLinkPnl.Visibility = Visibility.Collapsed;
xRunScriptPnl.Visibility = Visibility.Collapsed;
xRecordingScreenPnl.Visibility = Visibility.Collapsed;
xPushToDevicePnl.Visibility = Visibility.Collapsed;
xPullFromDevicePnl.Visibility = Visibility.Collapsed;
xSetClipboardTextPnl.Visibility = Visibility.Collapsed;

switch (mAct.MobileDeviceAction)
{
Expand Down Expand Up @@ -272,7 +281,7 @@ private void SetControlsView()
break;
case ActMobileDevice.eMobileDeviceAction.OpenDeeplink:
xDeepLinkPnl.Visibility = Visibility.Visible;

break;
case ActMobileDevice.eMobileDeviceAction.CloseApp:
case ActMobileDevice.eMobileDeviceAction.OpenApp:
Expand All @@ -292,7 +301,18 @@ private void SetControlsView()
break;

case ActMobileDevice.eMobileDeviceAction.StopRecordingScreen:
xRecordingScreenPnl.Visibility = Visibility.Visible;
xRecordingScreenPnl.Visibility = Visibility.Visible;
break;

case ActMobileDevice.eMobileDeviceAction.PushFileToDevice:
xPushToDevicePnl.Visibility = Visibility.Visible;
break;

case ActMobileDevice.eMobileDeviceAction.PullFileFromDevice:
xPullFromDevicePnl.Visibility = Visibility.Visible;
break;
case ActMobileDevice.eMobileDeviceAction.SetClipboardText:
xSetClipboardTextPnl.Visibility = Visibility.Visible;
break;
}
}
Expand Down
37 changes: 28 additions & 9 deletions Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,40 @@ public ePressKey MobilePressKey
OnPropertyChanged(nameof(MobilePressKey));
}
}
public ActInputValue Script
//public ActInputValue Script
//{

Check warning on line 118 in Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs#L118

Remove this commented out code.
// get
// {
// return GetOrCreateInputParam(nameof(Script));
// }
// set
// {
// AddOrUpdateInputParamValue(nameof(Script), value.ToString());
// OnPropertyChanged(nameof(Script));
// }
//}
public ActInputValue URLName
{
get
{
return GetOrCreateInputParam(nameof(Script));
return GetOrCreateInputParam(nameof(URLName), "your-deep-link-url");
}
set
{
AddOrUpdateInputParamValue(nameof(Script), value.ToString());
OnPropertyChanged(nameof(Script));
AddOrUpdateInputParamValue(nameof(URLName), value.ToString());
OnPropertyChanged(nameof(URLName));
}
}
public ActInputValue URLName
public ActInputValue LocalFile
{
get
{
return GetOrCreateInputParam(nameof(URLName));
return GetOrCreateInputParam(nameof(LocalFile), "/local/path/to/file.txt");
}
set
{
AddOrUpdateInputParamValue(nameof(URLName), value.ToString());
OnPropertyChanged(nameof(URLName));
AddOrUpdateInputParamValue(nameof(LocalFile), value.ToString());
OnPropertyChanged(nameof(LocalFile));
}
}
public ActInputValue X1
Expand Down Expand Up @@ -441,7 +453,14 @@ public enum eMobileDeviceAction
StopRecordingScreen,
[EnumValueDescription("Hide Keyboard")]
HideKeyboard,

[EnumValueDescription("Push File To Device")]
PushFileToDevice,
[EnumValueDescription("Pull File From Device")]
PullFileFromDevice,
[EnumValueDescription("Set To Clipboard Text")]
SetClipboardText,
[EnumValueDescription("Get Specific Performance Data")]
GetSpecificPerformanceData
}

public enum ePressKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,8 @@ private void MobileDeviceActionHandler(ActMobileDevice act)
RotateSimulation();
break;

case ActMobileDevice.eMobileDeviceAction.RunScript: // need to fix
RunScript(act.Script.ValueForDriver);
case ActMobileDevice.eMobileDeviceAction.RunScript:
RunScript(act.ActionInput.ValueForDriver);
break;

case ActMobileDevice.eMobileDeviceAction.StartRecordingScreen:
Expand All @@ -1280,6 +1280,18 @@ private void MobileDeviceActionHandler(ActMobileDevice act)
HideKeyboard();
break;

case ActMobileDevice.eMobileDeviceAction.PushFileToDevice:
PushFileToDevice(act.LocalFile.ValueForDriver);
break;

case ActMobileDevice.eMobileDeviceAction.PullFileFromDevice:
PullFileFromDevice(act.LocalFile.ValueForDriver, act.ActionInput.ValueForDriver);
break;

case ActMobileDevice.eMobileDeviceAction.SetClipboardText:
SetClipboardText(act.ActionInput.ValueForDriver);
break;

default:
throw new Exception("Action unknown/not implemented for the Driver: '" + this.GetType().ToString() + "'");
}
Expand Down Expand Up @@ -3873,7 +3885,7 @@ public void RunScript(string script)
}
catch (Exception ex)
{
throw new($"An error occurred: {ex.Message}");
throw new($"An error occurred: {ex.Message}");
}
}
public void StartRecordingScreen()
Expand All @@ -3890,7 +3902,7 @@ public void StartRecordingScreen()

}
}

public void StopRecordingScreen(string path)
{
string videoBase64 = ((AndroidDriver)Driver).StopRecordingScreen();
Expand Down Expand Up @@ -3918,5 +3930,61 @@ public void HideKeyboard()

}
}
public void PushFileToDevice(string localFilePath)
{

byte[] fileContent = System.IO.File.ReadAllBytes(localFilePath);
string fileName = Path.GetFileName(localFilePath);
if (Driver is IOSDriver)
{
((IOSDriver)Driver).PushFile($"Documents/{fileName}", fileContent);
}
else
{
((AndroidDriver)Driver).PushFile($"/sdcard/Download/{fileName}", fileContent);
}

}

public void PullFileFromDevice(string localFilePath, string fileName)
{

byte[] fileContent;

if (Driver is IOSDriver)
{
fileContent = ((IOSDriver)Driver).PullFile($"Documents/{fileName}");
}
else if (Driver is AndroidDriver)
{
fileContent = ((AndroidDriver)Driver).PullFile($"/sdcard/Download/{fileName}");
}
else
{
throw new InvalidOperationException("Driver must be either an IOSDriver or AndroidDriver");
}

// Save the file content to the local file path
System.IO.File.WriteAllBytes($"{localFilePath}{fileName}", fileContent);
}
public void SetClipboardText(string text)
{
//((IOSDriver)Driver).SetClipboardText(text);
((AndroidDriver)Driver).SetClipboardText(text, "");

}
public IList<object> GetSpecificPerformanceData(string packageName, string specificData) //"memoryinfo"
{
IList<object> perfData = ((AndroidDriver)Driver).GetPerformanceData(packageName, specificData, 10);
//IList<string> perfDataStrings = perfData.Select(item => item.ToString()).ToList();
return perfData;
}
public List<LogEntry> GetDeviceLogs(string logType) //working only on android device "logcat" for IOS "syslog"
{
//ILogs logs = Driver.Manage().Logs;

//return logs.GetLog(logType).ToList();
return Driver.Manage().Logs.GetLog(logType).ToList();
}
}
}

0 comments on commit 7dc495d

Please sign in to comment.