配置 Json 和 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

C#程式碼建立一個遠端 webdriver

// 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;