This repository was archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeleniumTools.cs
More file actions
137 lines (117 loc) · 4.73 KB
/
SeleniumTools.cs
File metadata and controls
137 lines (117 loc) · 4.73 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Created by Ranorex
* User: copresnik
* Date: 07.03.2017
* Time: 16:13
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using System.Diagnostics;
using System.Xml;
using WinForms = System.Windows.Forms;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Reporting;
using Ranorex.Core.Testing;
namespace RanorexDoesSelenium
{
/// <summary>
/// Description of SeleniumTools.
/// </summary>
[TestModule("B92BB854-2418-41AD-9FBB-F630562D0A98", ModuleType.UserCode, 1)]
public class SeleniumTools : ITestModule
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public SeleniumTools()
{
// Do not delete - a parameterless constructor is required!
}
/// <summary>
/// Performs the playback of actions in this module.
/// </summary>
/// <remarks>You should not call this method directly, instead pass the module
/// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
/// that will in turn invoke this method.</remarks>
void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;
Keyboard.DefaultKeyPressTime = 100;
Delay.SpeedFactor = 1.0;
}
/// <summary>
/// Starts an external process and waits for it to finish
/// </summary>
/// <param name="command">Process to be executed</param>
/// <param name="args">Arguments for the process</param>
/// <param name="workdir">Working Directory</param>
public void RunTestSynchronized(string command, string args, string workdir)
{
Report.Info("Selenium", "Starting " + command + " with Arguments " + args + " in " + workdir);
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = command;
psi.Arguments = args;
psi.WorkingDirectory = workdir;
try
{
var proc = Process.Start(psi);
proc.WaitForExit();
Report.Info("Selenium", "Done!");
}
catch(Exception e)
{
Report.Error("Selenium", "Could not start Selenium Test\n" + e.Message);
}
}
/// <summary>
/// Opens a JUNIT report and adds its results to the Ranorex Report
/// </summary>
/// <param name="workdir">The directory where the report file is located</param>
/// <param name="fileName">Name of the report file</param>
public void ParseExtTestResults(string workdir, string fileName)
{
XmlDocument xdoc = new XmlDocument();
try
{
xdoc.Load(workdir + fileName);
XmlNode xtestsuite = xdoc.SelectSingleNode("/testsuite");
XmlNodeList testcases = xdoc.SelectNodes("/testsuite/testcase");
string sHead = string.Format("External Selenium Test completed. {0} out of {1} test cases successful",
Int32.Parse(xtestsuite.Attributes["tests"].Value) - Int32.Parse(xtestsuite.Attributes["failures"].Value),
Int32.Parse(xtestsuite.Attributes["tests"].Value));
TestReport.BeginTestEntryContainer(1, "Selenium Test Suite (external)", ActivityExecType.Execute, TestEntryActivityType.TestCase);
TestReport.BeginSmartFolderContainer("Selenium", sHead);
Report.Info("Selenium", "Parsing Results...");
foreach(XmlNode n in testcases)
{
Ranorex.Core.Reporting.TestReport.BeginTestCaseContainer(n.Attributes["classname"].Value + "." + n.Attributes["name"].Value);
Ranorex.Core.Reporting.TestReport.BeginTestModule("Module " + n.Attributes["name"].Value);
if(n.SelectSingleNode("failure") != null)
{
Report.Failure("Selenium", "Test case " + n.Attributes["name"].Value + " (" + n.Attributes["classname"].Value + ") \n" +
n.SelectSingleNode("failure").Attributes["message"].Value);
Ranorex.Core.Reporting.TestReport.EndTestModule();
Ranorex.Core.Reporting.TestReport.EndTestCaseContainer(TestResult.Failed);
continue;
}
Report.Success("Selenium", "Test case " + n.Attributes["name"].Value + " (" + n.Attributes["classname"].Value + ")");
Ranorex.Core.Reporting.TestReport.EndTestModule();
Ranorex.Core.Reporting.TestReport.EndTestCaseContainer(TestResult.Passed);
}
TestReport.EndTestCaseContainer();
TestReport.EndTestEntryContainer();
}
catch(Exception e)
{
Report.Error("Selenium", "Error reading Results\n"+e.Message);
}
}
}
}