forked from florentbr/SeleniumBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhantomJSDriver.cs
More file actions
72 lines (63 loc) · 1.93 KB
/
PhantomJSDriver.cs
File metadata and controls
72 lines (63 loc) · 1.93 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
using Selenium.Core;
using System;
using System.Net;
using System.Runtime.InteropServices;
namespace Selenium {
/// <summary>
/// Web driver for PhantomJS (Headless browser)
/// </summary>
/// <example>
///
/// VBScript:
/// <code lang="vbs">
/// Class Script
/// Dim driver
///
/// Sub Class_Initialize
/// Set driver = CreateObject("Selenium.PhantomJSDriver")
/// driver.Get "http://www.google.com"
/// End Sub
///
/// Sub Class_Terminate
/// driver.Quit
/// End Sub
/// End Class
///
/// Set s = New Script
/// </code>
///
/// VBA:
/// <code lang="vbs">
/// Public Sub Script()
/// Dim driver As New PhantomJSDriver
/// driver.Get "http://www.google.com"
/// ...
/// driver.Quit
/// End Sub
/// </code>
///
/// </example>
[ProgId("Selenium.PhantomJSDriver")]
[Guid("0277FC34-FD1B-4616-BB19-0809389E78C4")]
[ComVisible(true), ClassInterface(ClassInterfaceType.None)]
public class PhantomJSDriver : WebDriver, ComInterfaces._WebDriver {
const string BROWSER_NAME = "phantomjs";
public PhantomJSDriver()
: base(BROWSER_NAME) { }
internal static IDriverService StartService(WebDriver wd) {
ExtendCapabilities(wd, false);
var svc = new DriverService();
svc.AddArgument("--webdriver=" + svc.IPEndPoint.ToString());
svc.AddArgument("--webdriver-loglevel=ERROR");
svc.AddArgument("--ignore-ssl-errors=true");
svc.Start("phantomjs.exe");
return svc;
}
internal static void ExtendCapabilities(WebDriver wd, bool remote) {
var capa = wd.Capabilities;
capa.BrowserName = "phantomjs";
if (wd.Arguments.Count > 0)
capa["phantomjs.cli.args"] = wd.Arguments;
}
}
}