garthenweb / react-native-e2etest

React Native example project to execute e2e tests with Appium and Jest
60 stars 18 forks source link

Appium in multi screen #8

Open gandarain opened 4 years ago

gandarain commented 4 years ago

Hi, Thanks for your information about appium. I want to ask you something. Lets say I have 2 screens, Login Screen and Home Screen. Login Screen will loaded first then Home Screen In Login screen I have accessibilityLabel fieldEmail and buttonLogin. In Home Screen I have accessibilityLabel buttonHome. How to tell appium, we need access buttonHome when Home Screen loaded?

This is my code

/* eslint-disable no-undef */
import wd from 'wd'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
const PORT = 4723
const config = {
  platformName: 'Android',
  deviceName: 'Pixel 3a XL API 29',
  app: '/Users/gandahalojasa/Documents/Project/Learn/Appium_React_Native/android/app/build/outputs/apk/debug/app-debug.apk'
}
const driver = wd.promiseChainRemote('localhost', PORT)

beforeAll(async () => {
  await driver.init(config)
  await driver.sleep(4000)
}) // Sometime for the app to load

test('login screen test', async () => {
  expect(await driver.hasElementByAccessibilityId('fieldEmail')).toBe(true)
  await driver.elementByAccessibilityId('fieldEmail').type('gandarainpanjaitan@gmail.com')
  expect(await driver.hasElementByAccessibilityId('buttonLogin')).toBe(true)
  const element = await driver.elementByAccessibilityId('buttonLogin')
  await element.click()
  expect(await driver.hasElementByAccessibilityId('notHere')).toBe(false)
})

test('home screen test', async () => {
  expect(await driver.hasElementByAccessibilityId('buttonHome')).toBe(true)
  const element = await driver.elementByAccessibilityId('buttonHome')
  await element.click()
})
robto09 commented 4 years ago

Hi, Thanks for your information about appium. I want to ask you something. Lets say I have 2 screens, Login Screen and Home Screen. Login Screen will loaded first then Home Screen In Login screen I have accessibilityLabel fieldEmail and buttonLogin. In Home Screen I have accessibilityLabel buttonHome. How to tell appium, we need access buttonHome when Home Screen loaded?

This is my code

/* eslint-disable no-undef */
import wd from 'wd'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
const PORT = 4723
const config = {
  platformName: 'Android',
  deviceName: 'Pixel 3a XL API 29',
  app: '/Users/gandahalojasa/Documents/Project/Learn/Appium_React_Native/android/app/build/outputs/apk/debug/app-debug.apk'
}
const driver = wd.promiseChainRemote('localhost', PORT)

beforeAll(async () => {
  await driver.init(config)
  await driver.sleep(4000)
}) // Sometime for the app to load

test('login screen test', async () => {
  expect(await driver.hasElementByAccessibilityId('fieldEmail')).toBe(true)
  await driver.elementByAccessibilityId('fieldEmail').type('gandarainpanjaitan@gmail.com')
  expect(await driver.hasElementByAccessibilityId('buttonLogin')).toBe(true)
  const element = await driver.elementByAccessibilityId('buttonLogin')
  await element.click()
  expect(await driver.hasElementByAccessibilityId('notHere')).toBe(false)
})

test('home screen test', async () => {
  expect(await driver.hasElementByAccessibilityId('buttonHome')).toBe(true)
  const element = await driver.elementByAccessibilityId('buttonHome')
  await element.click()
})

Did you run this code in ios?

gandarain commented 4 years ago

Hi, Thanks for your information about appium. I want to ask you something. Lets say I have 2 screens, Login Screen and Home Screen. Login Screen will loaded first then Home Screen In Login screen I have accessibilityLabel fieldEmail and buttonLogin. In Home Screen I have accessibilityLabel buttonHome. How to tell appium, we need access buttonHome when Home Screen loaded? This is my code

/* eslint-disable no-undef */
import wd from 'wd'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
const PORT = 4723
const config = {
  platformName: 'Android',
  deviceName: 'Pixel 3a XL API 29',
  app: '/Users/gandahalojasa/Documents/Project/Learn/Appium_React_Native/android/app/build/outputs/apk/debug/app-debug.apk'
}
const driver = wd.promiseChainRemote('localhost', PORT)

beforeAll(async () => {
  await driver.init(config)
  await driver.sleep(4000)
}) // Sometime for the app to load

test('login screen test', async () => {
  expect(await driver.hasElementByAccessibilityId('fieldEmail')).toBe(true)
  await driver.elementByAccessibilityId('fieldEmail').type('gandarainpanjaitan@gmail.com')
  expect(await driver.hasElementByAccessibilityId('buttonLogin')).toBe(true)
  const element = await driver.elementByAccessibilityId('buttonLogin')
  await element.click()
  expect(await driver.hasElementByAccessibilityId('notHere')).toBe(false)
})

test('home screen test', async () => {
  expect(await driver.hasElementByAccessibilityId('buttonHome')).toBe(true)
  const element = await driver.elementByAccessibilityId('buttonHome')
  await element.click()
})

Did you run this code in ios?

in run this code on android emulator