配置 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;