C 中的配置和使用
組態
在以下段落中,每個瀏覽器都有一個示例,用於 Json 中的配置和 C#中的設定。
此示例希望你在路徑變數和瀏覽器中安裝所有驅動程式。
Microsoft Edge
C#程式碼建立一個遠端 webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Edge();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Json 中的節點配置
{
"browserName":"MicrosoftEdge",
"platform": "WINDOWS",
"maxIstances": 1,
"seleniumProtocol": "WebDriver"
}
Chrome
C#程式碼建立一個遠端 webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Chrome();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Json 中的節點配置
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Firefox
C#程式碼建立一個遠端 webdriver
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities and chosing browser
capabiliteiten = DesiredCapabilities.Firefox();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Json 中的節點配置
{
"browserName": "firefox",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
Opera
用於建立遠端 webdriver 的 C#程式碼這適用於 OperaChromium
// Defining webdriver variable
RemoteWebDriver _webDriver;
// Creating Capabilities
capabiliteiten = new DesiredCapabilities();
// Setting platform
capabiliteiten.Platform = new Platform(PlatformType.Windows);
// Chosing browser
capabiliteiten.SetCapability(CapabilityType.BrowserName, "operablink");
// Requesting remote webdriver
_webDriver = new RemoteWebDriver(_gridServerUri, capabiliteiten);
Json 中的節點配置
{
"browserName": "operablink",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
平臺型別可以是以下之一:
- PlatformType.Android;
- PlatformType.Any;
- PlatformType.Linux;
- PlatformType.Mac;
- PlatformType.Unix;
- PlatformType.Vista;
- PlatformType.Windows;
- PlatformType.WinNT;
- PlatformType.XP;