我只是在设置排毒,用户可能会出错......话虽如此,我认为我做对了。我有一个 TextInput 元素,其中 accessibilityLabel 和 testID 都设置为电子邮件。但是,detox 找不到带有 by.id 或 by.label 的 UI 元素。奇怪的是,我可以在 xcode 的视图层次结构中找到我的标识符。我不知道从这里去哪里?我附上了视图层次结构的屏幕截图。
Detox、Node、Device、Xcode 和 macOS 版本
- 排毒:7.3.3
- 本机:0.54.2
- 节点:8.11.1
- 设备:iPhone 7
- Xcode:9.3
- macOS:10.13.3
排毒测试 如您所见,我正在尝试使用 by.label 和 by.id。我的测试是:
describe('Boot and sign in', () => {
beforeEach(async () => {
await device.reloadReactNative();
});
it('should have welcome screen', async () => {
await expect(element(by.label('Login'))).toBeVisible();
});
it('should show login screen after tap', async () => {
await element(by.label('Login')).tap();
await expect(element(by.label('login-signin'))).toBeVisible();
});
it('should sign in and land on the homepage', async () => {
await element(by.label('email')).typeText('qa@integrationtest.com');
await element(by.label('password')).typeText('aaaaaa');
await element(by.label('Sign in button')).tap();
await expect(element(by.label('HOME'))).toBeVisible();
});
it('should sign in and land on the homepage', async () => {
await element(by.id('email')).typeText('qa@integrationtest.com');
await element(by.id('password')).typeText('aaaaaa');
await element(by.id('Sign in button')).tap();
await expect(element(by.id('HOME'))).toBeVisible();
});
});
排毒日志
detox test
node_modules/.bin/jest e2e --config=e2e/config.json --runInBand --testNamePattern='^((?!:android:).)*$'
server listening on localhost:64077...
: Searching for device matching iPhone 7...
: Uninstalling com.craftsy.membership...
: com.craftsy.membership uninstalled
4: Installing /Users/steph.milovic/dev/craftsy-components/workspaces/membership/ios/Build/Build/Products/Debug-iphonesimulator/Membe ship.app...
4: /Users/steph.milovic/dev/craftsy-components/workspaces/membership/ios/Build/Build/Products/Debug-iphonesimulator/Membership.app i stalled
: Terminating com.craftsy.membership...
: com.craftsy.membership terminated
: Launching com.craftsy.membership...
6: com.craftsy.membership launched. The stdout and stderr logs were recreated, you can watch them with:
tail -F $HOME/Library/Developer/CoreSimulator/Devices/C978D6DE-8373-4550-B3C9-25A8FB9FDB99/data/tmp/detox.last_launch_app_lo .{out,err}
FAIL e2e/app.test.js (18.811s)
Boot and sign in
✓ should have welcome screen (1613ms)
✓ should show login screen after tap (2287ms)
✕ should sign in and land on the homepage (1333ms)
● Boot and sign in › should sign in and land on the homepage
Error: Cannot find UI element.
Exception with Action: {
"Action Name" : "Type 'qa@integrationtest.com'",
"Element Matcher" : "(((((kindOfClass('UILabel') || kindOfClass('UITextField') || kindOfClass('UITextView')) && hasText('Enter your email...')) || (kindOfClass('RCTTextView') && an object with accessibilityLabel "Enter your email...")) && !(kindOfClass('RCTScrollView'))) || (kindOfClass('UIScrollView') && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && ancestorThatMatches(((((kindOfClass('UILabel') || kindOfClass('UITextField') || kindOfClass('UITextView')) && hasText('Enter your email...')) || (kindOfClass('RCTTextView') && an object with accessibilityLabel "Enter your email...")) && kindOfClass('RCTScrollView'))))))",
"Recovery Suggestion" : "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it accurately matches element."
}
Error Trace: [
{
"Description" : "Interaction cannot continue because the desired element was not found.",
"Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
"Error Code" : "0",
"File Name" : "GREYElementInteraction.m",
"Function Name" : "-[GREYElementInteraction matchedElementsWithTimeout:error:]",
"Line" : "124"
}
]
at Client.execute (../node_modules/detox/src/client/Client.js:72:13)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 2 passed, 3 total
Snapshots: 0 total
Time: 19.717s
Ran all test suites matching /e2e/i with tests matching "^((?!:android:).)*$".
child_process.js:644
throw err;
^
Error: Command failed: node_modules/.bin/jest e2e --config=e2e/config.json --runInBand --testNamePattern='^((?!:android:).)*$'
at checkExecSyncError (child_process.js:601:13)
at Object.execSync (child_process.js:641:13)
at runJest (/usr/local/lib/node_modules/detox/local-cli/detox-test.js:110:6)
at run (/usr/local/lib/node_modules/detox/local-cli/detox-test.js:67:7)
at Object.<anonymous> (/usr/local/lib/node_modules/detox/local-cli/detox-test.js:54:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)