Skip to content

Commit 4ce456d

Browse files
committed
adding some Chrome fixes and new scripts
1 parent c435b5a commit 4ce456d

11 files changed

+275
-112
lines changed

3rdParty/CheckMarx/2.6.3_WSDL_files/Util - CheckMarx Rule and Guidance Viewer.h2

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?xml version="1.0"?>
2-
<H2>
3-
<SourceCode>var topPanel = "Util - CheckMarx Rule and Guidance Viewer".popupWindow(1000, 600).insert_LogViewer();
1+
var topPanel = "Util - CheckMarx Rule and Guidance Viewer".popupWindow(1000, 600).insert_LogViewer();
42
//var topPanel = panel.add_Panel(true);
53
var settingsPanel = topPanel.insert_Above(40,"Settings");
64
var treeView = topPanel.add_TreeView_with_PropertyGrid().sort();
@@ -11,11 +9,11 @@ var cxPortal = new CxPortalWebService();
119

1210
settingsPanel.add_Label("Server:",2).append_TextBox(cxPortal.Url).align_Right();
1311
//.widthAdd(-100)
14-
//.append_Link("Connect", ()=&gt;{});
12+
//.append_Link("Connect", ()=>{});
1513

1614
"cxSessionId".o2Cache(null);
1715
var sessionId = "cxSessionId".o2Cache(
18-
()=&gt;{
16+
()=>{
1917
var user = "What user do you want to use".askUser();
2018
var pwd = "What is the pwd for user {0}".format(user).askUser();
2119

@@ -42,19 +40,19 @@ var checkMark_Data = "_CheckMark_Data".tempDir(false);
4240

4341

4442
var queryQueryCollection = (CxQueryCollectionResponse)"CxQueryCollectionResponse".o2Cache(
45-
()=&gt;{
43+
()=>{
4644
"Loading data from GetQueryCollection (its about 2.5Mb".debug();
4745
var queryCollectionFile = checkMark_Data.pathCombine("WS_GetQueryCollection.xml");
4846
var response = cxPortal.GetQueryCollection(sessionId);
4947
response.saveAs(queryCollectionFile);
50-
return queryCollectionFile.load&lt;CxQueryCollectionResponse&gt;();
48+
return queryCollectionFile.load<CxQueryCollectionResponse>();
5149
});
5250

5351

54-
Action&lt;long&gt; showCweData =
55-
(cweId)=&gt;{
52+
Action<long> showCweData =
53+
(cweId)=>{
5654
O2Thread.mtaThread(
57-
()=&gt;{
55+
()=>{
5856
browser.showMessage("Loading CweId: {0}".format(cweId));
5957
var cweHtml = cxPortal.GetQueryDescription(sessionId, (int)cweId)
6058
.QueryDescription.saveWithExtension(".html");
@@ -64,15 +62,15 @@ Action&lt;long&gt; showCweData =
6462
};
6563

6664

67-
treeView.afterSelect&lt;CxWSQuery&gt;(
68-
(query)=&gt;{
65+
treeView.afterSelect<CxWSQuery>(
66+
(query)=>{
6967

7068
codeViewer.set_Text(query.Source, ".cs");
7169
showCweData(query.Cwe);
7270
});
7371

7472
treeView.beginUpdate();
75-
var queryGroupMappings = new Dictionary&lt;string, List&lt;CxWSQueryGroup&gt;&gt;();
73+
var queryGroupMappings = new Dictionary<string, List<CxWSQueryGroup>>();
7674
foreach(var queryGroup in queryQueryCollection.QueryGroups)
7775
queryGroupMappings.add(queryGroup.LanguageName, queryGroup);
7876

@@ -125,6 +123,3 @@ return response;
125123
*/
126124
//O2File:CxPortalWebService.cs
127125
//O2Ref:System.Web.Services.dll
128-
</SourceCode>
129-
<ReferencedAssemblies />
130-
</H2>

3rdParty/CheckMarx/API_IE_CxWebClient.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,25 @@ namespace O2.XRules.Database.APIs
1616

1717
public class API_IE_CxWebClient : API_IE_ExecutionGUI
1818
{
19+
public string DEFAULT_SERVER = "https://www.cxprivatecloud.com";
1920

2021
public API_IE_CxWebClient(WatiN_IE ie) : base(ie)
2122
{
22-
config();
23+
config(DEFAULT_SERVER);
24+
}
25+
public API_IE_CxWebClient(WatiN_IE ie, string targetServer) : base(ie)
26+
{
27+
config(targetServer);
2328
}
2429

2530
public API_IE_CxWebClient(Control hostControl) : base(hostControl)
2631
{
27-
config();
32+
config(DEFAULT_SERVER);
2833
}
2934

30-
public void config()
35+
public void config(string targetServer)
3136
{
32-
this.TargetServer = "https://www.cxprivatecloud.com";
37+
this.TargetServer = targetServer;
3338
API_IE_CxWebClient_HelperMethods.ie = this.ie;
3439
}
3540
}
@@ -41,8 +46,7 @@ public static class API_IE_CxWebClient_Actions
4146
public static API_IE_ExecutionGUI homepage(this API_IE_CxWebClient cxWeb)
4247
{
4348
return cxWeb.open("");
44-
}
45-
49+
}
4650

4751

4852
/*[ShowInGui(Folder ="links")]
@@ -70,13 +74,28 @@ public static class API_IE_CxWebClient_HelperMethods
7074
{
7175
public static WatiN_IE ie;
7276

77+
public static API_IE_CxWebClient login(this API_IE_CxWebClient cxClient, ICredential credential)
78+
{
79+
return cxClient.login(credential.UserName, credential.Password);
80+
}
81+
7382
public static API_IE_CxWebClient login(this API_IE_CxWebClient cxClient, string username, string password)
7483
{
75-
cxClient.open("/CxWebClient/login.aspx");
76-
ie.field("txtUserName").value(username);
77-
ie.field("txtPassword").value(password);
78-
ie.button("Login").click();
84+
if (cxClient.loggedIn())
85+
"[API_IE_CxWebClient][login] user already logged in, skipping login".info();
86+
else
87+
{
88+
cxClient.open("/CxWebClient/login.aspx");
89+
ie.field("txtUserName").value(username);
90+
ie.field("txtPassword").value(password);
91+
ie.button("Login").click();
92+
}
7993
return cxClient;
8094
}
95+
96+
public static bool loggedIn(this API_IE_CxWebClient cxClient)
97+
{
98+
return ie.hasLink("Logout"); // better detection modes will be needed
99+
}
81100
}
82101
}

3rdParty/Chrome/API_ChromeDriver.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
22
using System.Linq;
33
using System.Collections.Generic;
4-
4+
using O2.DotNetWrappers.ExtensionMethods;
5+
using OpenQA.Selenium.Remote;
56
using OpenQA.Selenium.Chrome;
67
using OpenQA.Selenium.IE;
78
using OpenQA.Selenium;
@@ -13,13 +14,29 @@ public class API_ChromeDriver
1314
{
1415

1516
}
16-
17+
1718
public static class API_ChromeDriver_ExtensionMethods
1819
{
1920
public static ChromeDriver open(this ChromeDriver chromeDriver, string url)
2021
{
2122
chromeDriver.Navigate().GoToUrl(url);
2223
return chromeDriver;
2324
}
25+
26+
public static List<IWebElement> elements(this ChromeDriver chromeDriver)
27+
{
28+
return (from element in chromeDriver.FindElements(By.XPath("//*"))
29+
select element).toList();
30+
}
31+
public static List<string> ids(this List<IWebElement> elements)
32+
{
33+
return (from element in elements
34+
select element.GetAttribute("Id")).Distinct().toList().removeEmpty();
35+
}
36+
public static List<string> tagNames(this List<IWebElement> elements)
37+
{
38+
return (from element in elements
39+
select element.TagName).Distinct().toList();
40+
}
2441
}
2542
}

3rdParty/Chrome/API_Chrome_Hijack.cs

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
using O2.Kernel.ExtensionMethods;
1010
using O2.DotNetWrappers.DotNet;
1111
using O2.DotNetWrappers.ExtensionMethods;
12+
using O2.XRules.Database.Utils;
1213
using OpenQA.Selenium;
1314
using OpenQA.Selenium.Chrome;
15+
//O2File:API_Win32_Handle_Hijack.cs
1416
//O2Ref:Selenium\net40\WebDriver.dll
1517
//Installer:Selenium_Installer.cs!Selenium\net40\WebDriver.dll
1618

@@ -20,14 +22,17 @@ namespace O2.XRules.Database.APIs
2022
{
2123
public class API_Chrome_Hijack
2224
{
23-
public ChromeDriver ChromeDriver { get; set; }
24-
public ChromeOptions ChromeOptions { get; set; }
25-
public ChromeDriverService ChromeDriverService { get; set; }
26-
public Process ChromeDriverProcess { get; set; }
27-
public Process ChromeProcess { get; set; }
28-
public string ChromeDriver_Exe { get; set; }
29-
public string WebDriver_Folder { get; set; }
30-
public string ChromeDriverDownloadLink { get; set; }
25+
public ChromeDriver ChromeDriver { get; set; }
26+
public ChromeOptions ChromeOptions { get; set; }
27+
public ChromeDriverService ChromeDriverService { get; set; }
28+
public Process ChromeDriverProcess { get; set; }
29+
public Process ChromeProcess { get; set; }
30+
public Panel Panel_Chrome { get; set; }
31+
public Panel Panel_ChromeDriver { get; set; }
32+
public ascx_Simple_Script_Editor WebDriver_Script_Me { get; set; }
33+
public string ChromeDriver_Exe { get; set; }
34+
public string WebDriver_Folder { get; set; }
35+
public string ChromeDriverDownloadLink { get; set; }
3136

3237
public API_Chrome_Hijack()
3338
{
@@ -61,33 +66,83 @@ public API_Chrome_Hijack open_ChromeDriver()
6166

6267
return this;
6368
}
69+
70+
}
71+
72+
73+
public static class API_Chrome_Test_ExtensionMethods
74+
{
75+
public static ChromeDriver add_Chrome(this Panel targetPanel)
76+
{
77+
return new API_Chrome_Hijack()
78+
.open_ChromeDriver()
79+
.hijack_Chrome(targetPanel,true)
80+
.ChromeDriver;
81+
}
6482

65-
/*public IntPtr startChromeDriver()
83+
public static API_Chrome_Hijack add_Chrome_To_Panel(this API_Chrome_Hijack chromeHijack, Panel targetPanel)
6684
{
67-
"[setup_Chrome] start".info();
68-
//var selenium = new API_Selenium();
69-
//ChromeDriver = selenium.setTarget_Chrome();
70-
//ChromeDriver chromeDriverProcess = "ChromeDriver".process_WithName();
71-
//chromeHandle= getProcessWithParentHandle(chromeDriverProcess.Id).MainWindowHandle;
72-
return chromeHandle;
73-
}*/
85+
var chrome_Panel = targetPanel.add_GroupBox("Chrome").add_Panel();
86+
var chromeDriver_Panel = chromeHijack.Panel_Chrome.parent().insert_Below(150,"Chrome WebDriver");
87+
88+
return chromeHijack.hijack_Chrome (chrome_Panel,false)
89+
.hijack_ChromeDriver(chromeDriver_Panel);
90+
}
7491

75-
/*Func<IntPtr, IWebDriver> setup_Chrome =
76-
(targetHandle)=>{
77-
"[setup_Chrome] start".info();
78-
var selenium = new API_Selenium();
79-
selenium.setTarget_Chrome();
80-
chromeDriverProcess = "ChromeDriver".process_WithName();
81-
chromeHandle= getProcessWithParentHandle(chromeDriverProcess.Id).MainWindowHandle;
82-
chromeHandle.setParent(targetHandle);
83-
WinAPI.ShowWindow(chromeHandle, WinAPI.ShowWindowCommands.ShowMaximized);
84-
"[setup_Chrome] done".info();
85-
return selenium.WebDriver;
86-
};*/
87-
92+
public static API_Chrome_Hijack hijack_Chrome(this API_Chrome_Hijack chromeHijack, Panel targetPanel, bool hijackJustViewer)
93+
{
94+
if (chromeHijack.notNull() && chromeHijack.ChromeProcess.notNull() && targetPanel.notNull())
95+
{
96+
chromeHijack.Panel_Chrome = targetPanel;
97+
var hijackGui = chromeHijack.Panel_Chrome.add_Handle_HijackGui(false);
98+
if (hijackJustViewer)
99+
{
100+
hijackGui.hijackProcessWindow(chromeHijack.ChromeProcess,
101+
(mainWindowHandle)=>
102+
{
103+
// this doesn't work well now since the main chrome window (with the address bar) still gains focus)
104+
// need to look at how to capture and filter events from the child to the parent (and vice versa)
105+
//
106+
var targetWindow = mainWindowHandle.child_Windows().second();
107+
return targetWindow;
108+
109+
return mainWindowHandle; // for now hijack the whole thing
110+
});
111+
112+
}
113+
else
114+
hijackGui.hijackProcessMainWindow(chromeHijack.ChromeProcess);
115+
}
116+
return chromeHijack;
117+
}
118+
119+
public static API_Chrome_Hijack hijack_ChromeDriver(this API_Chrome_Hijack chromeHijack, Panel targetPanel)
120+
{
121+
if (chromeHijack.notNull() && chromeHijack.ChromeDriverProcess.notNull() && targetPanel.notNull())
122+
{
123+
chromeHijack.Panel_ChromeDriver = targetPanel;
124+
chromeHijack.Panel_ChromeDriver.add_Handle_HijackGui(false)
125+
.hijackProcessMainWindow(chromeHijack.ChromeDriverProcess);
126+
}
127+
return chromeHijack;
128+
}
129+
130+
public static API_Chrome_Hijack add_WebDriver_ScriptMe_To(this API_Chrome_Hijack chromeHijack, Panel targetPanel)
131+
{
132+
133+
chromeHijack.WebDriver_Script_Me = chromeHijack.ChromeDriver.script_Me(targetPanel);
134+
return chromeHijack;
135+
}
136+
137+
public static Win32_Handle_Hijack hijack_Process_Into_Panel(this API_Chrome_Hijack chromeHijack, Panel targetPanel, Process targetProcess)
138+
{
139+
var hijackGui = targetPanel.add_Handle_HijackGui(false)
140+
.hijackProcessMainWindow(targetProcess);
141+
return hijackGui;
142+
}
88143
}
89-
90-
public static class API_Chrome_Test_ExtensionMethods
144+
145+
public static class Process_Extra_ExtensionMethods
91146
{
92147
public static Process getProcessWithParentHandle(this Process process)
93148
{
@@ -100,7 +155,7 @@ public static Process getProcessWithParentHandle(this Process process)
100155
var foundProcess = procId.process_WithId();
101156
"foundProcess: {0}".debug(foundProcess);
102157
return foundProcess;
103-
};
158+
}
104159
"Failed to find process with id: {0} name: {0}".error(process.Id, process.ProcessName);
105160
}
106161
return null;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var chromeHijack = new API_Chrome_Hijack();
2+
chromeHijack.script_Me("chromeHijack").insert_LogViewer();
3+
chromeHijack.open_ChromeDriver();
4+
5+
//O2File:API_Chrome_Hijack.cs
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//var topPanel = panel.add_Panel(true);
2+
var topPanel = "Util - REPL IE (native) and Chrome (hijacked window)".popupWindow(1200,600);
3+
var browsersPanel = topPanel.insert_Above();
4+
var ie = browsersPanel.title("IE").add_IE();
5+
var chrome = browsersPanel.insert_Right().add_Chrome();
6+
7+
var repl = topPanel.add_Script();
8+
repl.add_InvocationParameter("ie", ie);
9+
repl.add_InvocationParameter("chrome", chrome);
10+
11+
var firstScript =
12+
@"chrome.open(""http://o2platform.com"");
13+
ie.open(""http://o2platform.com"");
14+
15+
//return ie;
16+
return chrome;
17+
18+
//O2Ref:" + @"WatiN.Core.1x.dll
19+
//O2Ref:" + @"WebDriver.dll
20+
//O2File:" + @"WatiN_IE_ExtensionMethods.cs
21+
//O2File:" + @"API_Chrome_Hijack.cs
22+
//O2File:" + @"API_ChromeDriver.cs
23+
";
24+
repl.onCompileExecuteOnce()
25+
.set_Code(firstScript);
26+
//chrome.open("http://o2platform.com");
27+
28+
//O2Ref:WatiN.Core.1x.dll
29+
//O2Ref:WebDriver.dll
30+
//O2File:WatiN_IE_ExtensionMethods.cs
31+
//O2File:API_Chrome_Hijack.cs
32+
//O2File:API_ChromeDriver.cs

0 commit comments

Comments
 (0)