webdriver.io启动多台设备的配置讲解

本文详细介绍了WebDriver.io中capabilities和服务的配置方法。capabilities用于指定浏览器连接信息,如浏览器名称、实例数量等;服务配置则用于自动化启动如chromedriver、appium等服务。文中还提供了配置示例,帮助读者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置所在的文件是wdio.conf.ts(如果你用的js,就是wdio.conf.js),一般新建的项目它的路径是在./test/wdio.conf.ts,这个文件是webdriver.io的所有配置信息.

配置一: capabilities

1.介绍

此配置主要配置的是你的连接信息,比如:你要连接chrome浏览器,你就需要传入browserName:‘chrome’,这样它就会去连接chrome浏览器.

注意: 它只是配置连接信息,并不是启动一个chrome浏览器或是去启动chromedriver

2.配置连接单个服务

export const config: Options.Testrunner = {
	......
	capabilities: [{
        // maxInstances can get overwritten per capability. So if you have an in-house Selenium
        // grid with only 5 firefox instances available you can make sure that not more than
        // 5 instances get started at a time.
        maxInstances: 5,
        //
        browserName: 'chrome',
        acceptInsecureCerts: true,
        // If outputDir is provided WebdriverIO can capture driver session logs
        // it is possible to configure which logTypes to include/exclude.
        // excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs
        // excludeDriverLogs: ['bugreport', 'server'],

        'goog:chromeOptions': {
            args: [
                // '--headless',
                '--disable-infobars',
                '--no-sandbox',
                '--disable-gpu',
                '--window-size=1024,768',
            ].concat(isCI ? ['--headless'] : [])    // run in headless mode on the CI server,
        }
    }],
	......
}

3.配置连接多个服务

export const config: Options.Testrunner = {
	......
	capabilities: {
		// 这里面就是配置你需要连接的服务
		// 连接chorme浏览器
		a: {
			prot: 9515,
			path: "/",
			capabilities: {
				browserName: 'chrome'
			}
		},
		// 连接appium
		b: {
			prot : 4723,
			path: '/wd/hub',
			capabilities: {
				'platformName': 'ios',
				......
			}
		}
	}
	......
}

4.如果你觉得这些配置有些麻烦,那可以去下面给的网站,根据需求自动生成配置

https://saucelabs.com/platform/platform-configurator

配置二: services

1.介绍

此配置主要是配置你需要webdriver.io帮你启动的服务,比如chromedriver,appium,启动这些服务时,要安装对应的依赖,同时如果你用这种方式帮你启动的话,你无需在向之前一样,chrome更新后去重新下载chromedriver.

2.配置单个服务

export const config: Options.Testrunner = {
	......
	// 启动chromedriver
	services: [‘chromedrvier’]
	......
}

3.配置多个服务

export const config: Options.Testrunner = {
	......
	// 启动chromedriver
	services: [["chromedriver", {
        port: 9515,
        hostname: "localhost"
    }], ["appium", { port: 4723, hostname: "localhost"}]],
	......
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值