-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathWorkFlow.cs
More file actions
99 lines (88 loc) · 3.37 KB
/
WorkFlow.cs
File metadata and controls
99 lines (88 loc) · 3.37 KB
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
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
using Castle.Core.Logging;
using TestStack.White.Configuration;
namespace TestStack.White.ScreenObjects.ScreenFlow
{
//TODO: Add the ability to run the tests at different speeds
//TODO: Dump of the screen shot when the test fails
//TODO: Taking screenshot and automationelement dump from VisualStudio class code
//TODO: Class diagram for Session, Work* etc classes
public class WorkFlow
{
private int step;
private int snapshots;
private Type currentScreenType = typeof (Nullable);
private readonly GraphWriter graph;
private readonly FlowWriter flow;
private readonly string directory;
private static readonly ILogger Logger = CoreConfigurationLocator.Get().LoggerFactory.Create(typeof(WorkFlow));
public WorkFlow(string name, string archiveLocation)
{
Log("Starting flow " + name);
directory = CreateNewDirectory(name, archiveLocation);
graph = new GraphWriter(string.Format(@"{0}\graph.dot", directory));
flow = new FlowWriter(string.Format(@"{0}\flow.dot", directory));
}
private static void Log(string format, params object[] args)
{
Logger.DebugFormat("± " + format, args);
}
private void TakeSnapShot()
{
string fileName = string.Format(@"{0}\{1}.png", directory, snapshots++);
CaptureScreenTo(fileName);
}
private static void CaptureScreenTo(string fileName)
{
using (var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format24bppRgb))
{
using (Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot))
{
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
}
bmpScreenshot.Save(fileName, ImageFormat.Png);
}
}
private string CreateNewDirectory(string flowName, string archiveLocation)
{
string result = string.Format(@"{0}\{1}", archiveLocation, flowName);
if (Directory.Exists(result)) Directory.Delete(result,true);
Directory.CreateDirectory(result);
return result;
}
public virtual void Stop()
{
TakeSnapShot();
Log("End of flow " + currentScreenType);
graph.Stop(currentScreenType);
flow.Stop(step, currentScreenType);
}
public virtual void Move(Type fromType, Type toType)
{
if(step == 0)
{
graph.Start(fromType);
flow.Start(step, fromType);
}
Log("[{0}] -> [{1}]", fromType, toType);
graph.AppendFlow(fromType, toType);
flow.AppendFlow(step, fromType, toType);
step++;
currentScreenType = toType;
}
public virtual void Error()
{
graph.AppendError();
flow.AppendError();
}
public virtual void Track()
{
TakeSnapShot();
}
}
}