Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VRT Baseline Load Fixed #3700

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@
<Frame x:Name="VRTPreviewBaselineImageFrame" Background="White" Height="400" Margin="5,20,5,10"></Frame>
</StackPanel>

<Label x:Name="xVRTNote" Style="{StaticResource $LabelStyle}" Grid.Row="13" Grid.ColumnSpan="2" Margin="0,10,0,0" VerticalAlignment="Bottom" Content="Note - Ensure that VRT details are entered in Configurations -> External Integrations -> VRT configurations."/>
<Label x:Name="xVRTNote" Style="{StaticResource $LabelStyle}" Width="auto" Grid.Row="13" Grid.ColumnSpan="2" Margin="0,10,0,0" VerticalAlignment="Bottom" Content="Note - Ensure that VRT details are entered in Configurations -> External Integrations -> VRT configurations."/>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ limitations under the License.
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
Expand Down Expand Up @@ -69,7 +71,25 @@ public VRTComparePage(GingerCore.Actions.ActVisualTesting mAct)
VRTCurrentBaselineImagePathTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(VRTAnalyzer.VRTSavedBaseImageFilenameString), true, true, UCValueExpression.eBrowserType.File, "png", BaseLineFileSelected_Click);
WeakEventManager<TextBoxBase, TextChangedEventArgs>.AddHandler(source: VRTCurrentBaselineImagePathTxtBox.ValueTextBox, eventName: nameof(TextBoxBase.TextChanged), handler: ValueTextBox_TextChanged);
UpdateBaseLineImage();
GetBaseLineImage();
Task.Run(async () =>
{
try
{
Dispatcher.Invoke(() =>
{
VRTPreviewBaselineImageFrame.ClearAndSetContent(new LoadingPage(
loadingLabel: "loading baseline image...",
width: 40,
height: 40,
fontSize: 15));
});
await LoadBaseLineImageAsync();
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Error while loading baseline image", ex);
}
});
GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xCreateBaselineCheckbox, CheckBox.IsCheckedProperty, mAct, nameof(mAct.CreateBaselineImage));

InitLayout();
Expand Down Expand Up @@ -359,32 +379,49 @@ private void UpdateBaseLineImage()
VRTBaseImageFrame.ClearAndSetContent(p);
}

private void GetBaseLineImage()
private async Task LoadBaseLineImageAsync()
{
try
{
if (!string.IsNullOrEmpty(mAct.previewBaselineImageName))
{
string previewBaselineImage = GingerCoreNET.GeneralLib.General.DownloadBaselineImage($"{WorkSpace.Instance.Solution.VRTConfiguration.ApiUrl}/{mAct.previewBaselineImageName}", mAct);
string FileName = General.GetFullFilePath(previewBaselineImage);
BitmapImage b = null;
if (File.Exists(FileName) && new FileInfo(FileName).Length > 0)
{
b = GetFreeBitmapCopy(FileName);
}
// send with null bitmap will show image not found
ScreenShotViewPage p = new ScreenShotViewPage("Preview Baseline Image", b);
VRTPreviewBaselineImageFrame.ClearAndSetContent(p);
}
else
if (string.IsNullOrEmpty(mAct.previewBaselineImageName))
{
Reporter.ToLog(eLogLevel.ERROR, "unable to fetch the baseline image");
return;
}

string imagePath = await GetBaseLineImageAsync();
Dispatcher.Invoke(() => SetBaseLineImage(imagePath));
}
catch(Exception ex)
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "unable to fetch the baseline image",ex);
}
Reporter.ToLog(eLogLevel.ERROR, "Error while loading baseline image", ex);
}
}

private Task<string> GetBaseLineImageAsync()
{
return GingerCoreNET.GeneralLib.General.DownloadBaselineImage(
ImageURL: $"{WorkSpace.Instance.Solution.VRTConfiguration.ApiUrl}/{mAct.previewBaselineImageName}",
mAct);
}

private void SetBaseLineImage(string imagePath)
{
if(string.IsNullOrEmpty(imagePath))
{
Reporter.ToLog(eLogLevel.ERROR, "unable to fetch the baseline image");
return;
}

string FileName = General.GetFullFilePath(imagePath);
BitmapImage? b = null;
if (File.Exists(FileName) && new FileInfo(FileName).Length > 0)
{
b = GetFreeBitmapCopy(FileName);
}
// send with null bitmap will show image not found
ScreenShotViewPage p = new ScreenShotViewPage("Preview Baseline Image", b);
VRTPreviewBaselineImageFrame.ClearAndSetContent(p);
prashelke marked this conversation as resolved.
Show resolved Hide resolved
}

private BitmapImage GetFreeBitmapCopy(String filePath)
Expand Down
5 changes: 4 additions & 1 deletion Ginger/Ginger/GeneralLib/LoadingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ namespace Ginger
/// </summary>
public partial class LoadingPage : Page
{
public LoadingPage(string loadingLabel = "Loading...")
public LoadingPage(string loadingLabel = "Loading...", double width = 80, double height = 80, double fontSize = 25)
{
InitializeComponent();

xProcessingLabel.Content = loadingLabel;
xProcessingLabel.FontSize = fontSize;
xProcessingIcon.Width = width;
xProcessingIcon.Height = height;
prashelke marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
15 changes: 6 additions & 9 deletions Ginger/GingerCoreNET/GeneralLib/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ limitations under the License.
using System.Reflection;
using System.Security;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;

namespace GingerCoreNET.GeneralLib
Expand Down Expand Up @@ -536,7 +537,7 @@ public static string DownloadImage(string ImageURL, Act act)
return currImagePath;
}

public static string DownloadBaselineImage(string ImageURL, Act act)
public static async Task<string> DownloadBaselineImage(string ImageURL, Act act)
{
String currImagePath = Act.GetScreenShotRandomFileName();
try
Expand All @@ -546,19 +547,15 @@ public static string DownloadBaselineImage(string ImageURL, Act act)
{
using (var fs = new FileStream(currImagePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
response.Content.CopyToAsync(fs).ContinueWith(
(discard) =>
{
fs.Close();
});
await response.Content.CopyToAsync(fs);
fs.Close();
}

return currImagePath;
}
}
catch (Exception ex)
{
act.Error += ex.Message;
act.Error += ex.Message;
Reporter.ToLog(eLogLevel.ERROR, "unable to fetch the baseline image");
}
return currImagePath;
}
Expand Down
Loading