首先,第一个屏幕是LoginScreen
,登录后我们可以看到底部导航器。
我以此方式创建了一个底部导航器,并在navigationOptions上将tabBartestID
设置为Transactions
。
const Tabs = createBottomTabNavigator(
{
Transactions: {
screen: createStackNavigator(
{
Transactions: {
screen: TransactionsView,
navigationOptions: {
header: null,
},
},
QueryResult: {
screen: QueryResultView,
navigationOptions: {
header: null,
},
},
RegisterResult: {
screen: RegisterResultView,
navigationOptions: {
header: null,
},
},
},
{
initialRouteName: 'Transactions',
},
),
navigationOptions: {
title: 'Transactions',
tabBarTestID: 'Transactions',
tabBarIcon: ({ tintColor }) => <Badge tintColor={tintColor} />,
},
}
}
当我使用detox
测试时,错误为Interaction cannot continue because the desired element was not found.
堆栈跟踪:
✕ navigate to transactions (66ms)
● Login & Generate Keys Sequence test › navigate to transactions
Cannot find UI element.
Exception with Action: {
"Action Name": "Tap",
"Element Matcher": "((!(kindOfClass('RCTScrollView')) && (respondsToSelector(accessibilityIdentifier) && accessibilityID('Tab Name'))) || (((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches(kindOfClass('RCTScrollView'))) && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches((respondsToSelector(accessibilityIdentifier) && accessibilityID('Tab Name'))))))",
"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"
}
]
这是我的测试:
describe('Login & Generate Keys Sequence test', () => {
// beforeEach(async () => {
// await device.reloadReactNative()
// device.shake();
// })
it('login screen should load', async () => {
await expect(element(by.id('loginView'))).toBeVisible()
})
it('login screen should have slogan', async () => {
await expect(element(by.text('Things Information Exchange'))).toBeVisible()
})
it('login screen should have password field', async () => {
await expect(element(by.id('password'))).toBeVisible()
})
it('login screen should have login button', async () => {
await expect(element(by.id('login'))).toBeVisible()
})
it('login screen should have generate keys button', async () => {
await expect(element(by.id('generateKeys'))).toBeVisible()
})
it('it should tap on generate keys button', async () => {
await element(by.id('generateKeys')).tap()
})
it('identity setup screen should have title', async () => {
await expect(element(by.text('Set your Identity Up'))).toBeVisible()
})
it('identity setup screen should have slogan', async () => {
await expect(
element(
by.text(
'Interactively expedite revolutionary ROI after bricks-and-clicks alignments.',
),
),
).toBeVisible()
})
it('identity setup screen should have password field', async () => {
await expect(element(by.id('newPassword'))).toBeVisible()
})
it('identity setup screen should have password suggestion', async () => {
await expect(
element(by.text('Your passphrase should be .. . . ')),
).toBeVisible()
})
it('identity setup screen should have generate keys circle', async () => {
await expect(element(by.id('keysSpinner'))).toBeVisible()
})
it('identity setup screen should have copy button', async () => {
await expect(element(by.id('copy'))).toBeVisible()
})
it('identity setup screen copy button should have correct text', async () => {
await expect(element(by.text('Copy to clipboard'))).toBeVisible()
})
it('identity setup screen should have license agreement toggle', async () => {
await expect(element(by.id('licenseToggle'))).toBeVisible()
})
it('identity setup screen should have finish button', async () => {
await expect(element(by.text('I‘m done here'))).toBeVisible()
})
it('identity setup screen should input new password', async () => {
await element(by.id('newPassword')).typeText('1234567890')
})
it('identity setup screen should generate keys', async () => {
await element(by.id('keysSpinner')).tap()
await element(by.id('keysSpinner')).tap()
})
// it('identity should wait for generating keys', async () => {
// TODO: wait for 2seconds
// await expect(element(by.text("Your keys Are generated"))).toBeVisible();
// })
it('identity setup screen should accept license agreement', async () => {
await element(by.id('licenseToggle')).tap()
})
it('identity setup screen should tap finish button', async () => {
await element(by.text('I‘m done here')).tap()
})
it('navigate to transactions', async () => {
await element(by.id('Transactions')).tap();
})
})
我也尝试等待2秒:
await waitFor(element(by.id('Transactions'))).toBeVisible().withTimeout(2000)