Test Configuration
Run your tests against multiple device configurations
You can change the configuration for a test suite with
test.use
. Note that config changes will start a new session when used within a test.describe
.import { test, expect } from '@appetize/playwright'
test.use({
config: {
publicKey: '<PUBLIC KEY >'
device: 'nexus5'
},
});
test('app works on nexus5', async ({ session }) => {
...
})
The current configuration can be accessed with the
config
argument in the testtest('my test', async ({ session, config }) => {
if (config.osVersion === '7.0') {
// do os 7.0 specific behaviour
} else {
}
})
You can also use this to skip tests
test.describe('iOS 16 features', () => {
// skip suite if osVersion is less than 16
test.skip(({ config }) => parseInt(config.osVersion) < 16);
test('some feature', async ({ session }) => { ... })
})
Projects allow you to run your entire test suite with different configurations. This is useful if you have a cross platform app or wish to test against a set of devices and/or osVersions.
Below are some examples that may fit your use case.
Runs tests under
tests/ios
for the iOS configuration, and tests/android
for the Android configurationconst config = {
// ...
projects: [
{
name: 'ios',
testDir: './tests/ios',
use: {
config: {
device: 'iphone14pro',
publicKey: '<IOS APP PUBLIC KEY>'
}
},
},
{
name: 'android',
testDir: './tests/android',
use: {
config: {
device: 'pixel6',
publicKey: '<ANDROID APP PUBLIC KEY>'
}
},
}
]
}
Runs the test suite against iOS 16 and iOS 15
const config = {
// ...
use: {
config: {
publicKey: '<PUBLIC KEY>'
}
},
projects: [
{
name: 'ios-16',
use: {
config: {
device: 'iphone14pro',
osVersion: '16',
}
},
},
{
name: 'ios-15',
use: {
config: {
device: 'iphone14pro',
osVersion: '15'
}
},
}
]
}
Runs the test suite against a Pixel 7 and a Pixel 6
const config = {
// ...
use: {
config: {
publicKey: '<PUBLIC KEY>'
}
},
projects: [
{
name: 'pixel7',
use: {
config: {
device: 'pixel7'
}
},
},
{
name: 'pixel6',
use: {
config: {
device: 'pixel6'
}
},
}
]
}
You can reference the current project configuration in your tests. This is useful if you need to change or skip a test based on a certain device
Last modified 4mo ago