/
Utils.cs
100 lines (96 loc) · 3.46 KB
/
Utils.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AppuimTestTools
{
public static class Utils
{
public static string GetDevice(string path)
{
string result = "";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = path + "\\adb.exe";
//要执行的程序名称
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
//可能接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;
//由调用程序获取输出信息
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "devices";
//不显示程序窗口
p.Start();
result += p.StandardOutput.ReadToEnd();
//p.BeginOutputReadLine();
p.WaitForExit();
while (p.ExitCode != 0)
{
result += p.StandardOutput.ReadToEnd();
Thread.Sleep(200);
}
p.Close();
return result;
}
public static void GetScreenShot(string path,string filename)
{
//string result = "";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = path + "\\adb.exe";
//要执行的程序名称
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
//可能接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;
//由调用程序获取输出信息
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "shell /system/bin/screencap -p /sdcard/" + filename;
//不显示程序窗口
p.Start();
//result += p.StandardOutput.ReadToEnd();
//p.BeginOutputReadLine();
p.WaitForExit();
while (p.ExitCode != 0)
{
//result += p.StandardOutput.ReadToEnd();
//Thread.Sleep(200);
}
p.Close();
return;
}
public static void SaveScreenShot(string path, string filename,string savepath)
{
//string result = "";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = path + "\\adb.exe";
//要执行的程序名称
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
//可能接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;
//由调用程序获取输出信息
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "pull /sdcard/"+filename+" " + savepath + "\\" + filename;
//不显示程序窗口
p.Start();
//result += p.StandardOutput.ReadToEnd();
//p.BeginOutputReadLine();
p.WaitForExit();
while (p.ExitCode != 0)
{
//result += p.StandardOutput.ReadToEnd();
//Thread.Sleep(200);
}
Thread.Sleep(500);
p.Close();
return;
}
}
public enum TestCaseStatus
{
通过测试,
验证测试
}
}