-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAppInitializer.cs
74 lines (65 loc) · 2.6 KB
/
AppInitializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xamarin.UITest;
using Xamarin.UITest.Configuration;
using Xamarin.UITest.Utils;
[assembly: System.Reflection.AssemblyVersionAttribute("0.0.0.0")]
namespace XamarinPipelineDemo.UITest
{
public static class AppInitializer
{
public static IApp StartApp(Platform platform)
{
if (platform == Platform.Android)
{
return ConfigureApp.Android
.Debug()
.EnableLocalScreenshots()
.ApkFileFromEnvironmentOrPreinstalledApp("com.demo.XamarinPipelineDemo")
.StartApp();
}
return ConfigureApp.iOS
.EnableLocalScreenshots()
.StartApp();
}
private static AndroidAppConfigurator ApkFileFromEnvironmentOrPreinstalledApp(
this AndroidAppConfigurator app,
string preinstalledAppName)
{
var envApkPath = "UITEST_APK_PATH";
var envKeystorePath = "UITEST_KEYSTORE_PATH";
var envKeystorePassword = "UITEST_KEYSTORE_PASSWORD";
var envKeyAlias = "UITEST_KEY_ALIAS";
var envKeyPassword = "UITEST_KEY_PASSWORD";
var allKeystoreEnvs = new[] { envKeystorePath, envKeystorePassword, envKeyAlias, envKeyPassword };
var allEnvs = allKeystoreEnvs.Concat(new[] { envApkPath }).ToArray();
var envDict = allEnvs.ToDictionary(envName => envName, envName => Environment.GetEnvironmentVariable(envName));
foreach(var entry in envDict)
{
Console.WriteLine($"DEMO_NOTE: envDict key='{entry.Key}' value='{entry.Value}'");
}
if(!string.IsNullOrWhiteSpace(envDict[envApkPath]))
{
Console.WriteLine($"DEMO_NOTE: using apk file");
app = app.ApkFile(envDict[envApkPath]);
}
else
{
Console.WriteLine($"DEMO_NOTE: using preinstalled app name");
app = app.InstalledApp(preinstalledAppName);
if(allKeystoreEnvs.All(envName => !string.IsNullOrWhiteSpace(envDict[envName])))
{
Console.WriteLine($"DEMO_NOTE: using keystore");
app = app.KeyStore(
envDict[envKeystorePath],
envDict[envKeystorePassword],
envDict[envKeyPassword],
envDict[envKeyAlias]);
}
}
return app;
}
}
}