How to use waitForValueToChange method in pyatom

Best Python code snippet using pyatom_python

AXClasses.py

Source:AXClasses.py Github

copy

Full Screen

...1002 """Convenience method to wait for a sheet to appear.1003 Returns: the sheet that appeared (element) or None1004 """1005 return self.waitForCreation(timeout, 'AXSheetCreated')1006 def waitForValueToChange(self, timeout=10):1007 """Convenience method to wait for value attribute of given element to1008 change.1009 Some types of elements (e.g. menu items) have their titles change,1010 so this will not work for those. This seems to work best if you set1011 the notification at the application level.1012 Returns: Element or None1013 """1014 # Want to identify that the element whose value changes matches this1015 # object's. Unique identifiers considered include role and position1016 # This seems to work best if you set the notification at the application1017 # level1018 callback = AXCallbacks.returnElemCallback1019 retelem = None1020 return self.waitFor(timeout, 'AXValueChanged', callback=callback, args=(retelem,))...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

...13 {14 options: { helloWorld: true }15 }16 )17 await waitForValueToChange(() => result.current.isLoading)18 expect(result.all).toMatchSnapshot()19 })20 test('getting from the cache', async () => {21 const { result } = renderHook(22 () => useThing(23 'EWhateverEntity',24 () => Promise.resolve('NEVER')25 ),26 { wrapper },27 {28 options: { helloWorld: true }29 }30 )31 expect(result.current.data).toBe('hello world')32 })33 test('dependend queries', async () => {34 const { result, waitForValueToChange } = renderHook(35 () => useThing(36 'EDependendEntity1',37 () => Promise.resolve('Cool, isn\'t it? 🙂')38 ),39 { wrapper }40 )41 await waitForValueToChange(() => result.current.isLoading)42 const { result: result2 } = renderHook(43 () => useThing(44 'EDependendEntity2',45 ({ options }) => Promise.resolve(`This text is passed through options from dependent entity "${options}"`),46 {47 skip: result.current.isLoading || result.current.isInitial,48 options: result.current.data49 }50 ),51 { wrapper }52 )53 await waitForValueToChange(() => result2.current.isLoading)54 expect(result2.current.data).toBe('This text is passed through options from dependent entity "Cool, isn\'t it? 🙂"')55 })56 test('initialData feature', async () => {57 const { result, waitForValueToChange } = renderHook(58 () => useThing(59 'EInitialDataEntity',60 () => Promise.resolve('Not initial anymore 🙃'),61 {62 initialData: ({ length = 5 }) => Array.from({ length }).map(() => 'A'),63 options: {64 length: 265 }66 }67 ),68 { wrapper }69 )70 expect(result.current.data).toEqual(['A', 'A'])71 await waitForValueToChange(() => result.current.isLoading)72 })73 test('dataMapper feature', async () => {74 const { result, waitForValueToChange } = renderHook(75 () => useThing(76 'EDataMapper',77 () => Promise.resolve([2, 4, 8]),78 {79 initialData: [],80 dataMapper: data => data.map(el => el * 2)81 }82 ),83 { wrapper }84 )85 await waitForValueToChange(() => result.current.isLoading)86 expect(result.current.mappedData).toEqual([4, 8, 16])87 })88 test('prevent multi fetching', async () => {89 let counter = 090 const { result, waitForValueToChange } = renderHook(91 () => useThing(92 'EMultiFetchingEntity',93 () => {94 counter += 195 return Promise.resolve(counter)96 },97 {98 options: { multiFetching: true }99 }100 ),101 { wrapper }102 )103 const { result: result2 } = renderHook(104 () => useThing(105 'EMultiFetchingEntity',106 () => {107 counter += 1108 return Promise.resolve(counter)109 },110 {111 options: { multiFetching: true }112 }113 ),114 { wrapper }115 )116 const { result: result3 } = renderHook(117 () => useThing(118 'EMultiFetchingEntity',119 () => {120 counter += 1121 return Promise.resolve(counter)122 },123 {124 options: { multiFetching: true }125 }126 ),127 { wrapper }128 )129 await waitForValueToChange(() => result.current.isLoading)130 expect(result.current.data).toEqual(1)131 expect(result2.current.data).toEqual(1)132 expect(result3.current.data).toEqual(1)133 })134 test('fetchMore feature', async () => {135 const MAX_ITEMS = 10136 const reducer = (state, { type, payload: data }, { toType }) => {137 if (type === toType(useThing.Types.Fulfilled)) {138 return {139 ...state,140 data: [141 ...(state?.data || []),142 ...(data || [])143 ]144 }145 }146 return state || {}147 }148 const { result, waitForValueToChange } = renderHook(149 () => useThing(150 'TFetchMoreEntity',151 ({ options: { limit, offset } }) => Promise.resolve(152 Array153 .from({ length: 10 })154 .map((_, index) => index)155 .slice(offset, limit + offset)156 ),157 {158 initialData: [],159 getFetchMore: ({ options: { limit, offset } }) => {160 if (limit + offset < MAX_ITEMS) {161 return { limit, offset: offset + limit }162 }163 return false164 },165 reducer,166 options: {167 limit: 5,168 offset: 0169 }170 }171 ),172 { wrapper }173 )174 await waitForValueToChange(() => result.current.isLoading)175 act(() => {176 result.current.fetchMore()177 })178 await waitForValueToChange(() => result.current.isLoading)179 expect(result.current.data.length).toBe(10)180 act(() => {181 result.current.fetchMore()182 })183 expect(result.current.data.length).toBe(10)184 })185 test('refetch feature', async () => {186 const { result, waitForValueToChange } = renderHook(187 () => useThing(188 'TRefetchEntity',189 () => Promise.resolve('hello world')190 ),191 { wrapper },192 {193 options: { helloWorld: true }194 }195 )196 await waitForValueToChange(() => result.current.isLoading)197 act(() => {198 result.current.refetch()199 })200 await waitForValueToChange(() => result.current.isLoading)201 expect(result.all).toMatchSnapshot()202 })203 test('debounce options changing', async () => {204 jest.useFakeTimers('modern')205 const debounceInterval = 1000206 const callback = jest.fn().mockImplementation(({ options }) => Promise.resolve(options))207 const { result, rerender, waitForValueToChange } = renderHook(208 props => useThing(209 'TDebounce',210 callback,211 {212 ...props,213 reducer: (state, { type, payload: data }, { toType }) => {214 if (type === toType('fulfilled')) {215 return {216 ...state,217 data: {218 ...state.data,219 [data.count]: data220 }221 }222 }223 return state || {}224 },225 selector: (state, { key, options }) => (226 state?.[key]?.data?.[options.count] || null227 )228 }229 ),230 {231 wrapper,232 initialProps: {233 debounceInterval,234 options: {235 count: 1236 }237 }238 }239 )240 await waitForValueToChange(() => result.current.isLoading)241 expect(result.current.data.count).toBe(1)242 expect(callback).toHaveBeenCalledTimes(1)243 rerender({244 debounceInterval,245 options: {246 count: 2247 }248 })249 rerender({250 debounceInterval,251 options: {252 count: 3253 }254 })255 rerender({256 debounceInterval,257 options: {258 count: 4259 }260 })261 act(() => jest.runAllTimers())262 await waitForValueToChange(() => result.current.isLoading)263 expect(callback).toHaveBeenCalledTimes(2)264 expect(result.current.data.count).toBe(4)265 jest.useRealTimers()266 })267 test('object reducer', async () => {268 const { result, waitForValueToChange } = renderHook(269 () => useThing(270 'TObjectReducer',271 () => Promise.resolve('hello world'),272 {273 reducer: {274 dictionary: {275 fulfilled: (state, { payload }) => ({276 ...state,277 data: {278 hello: payload279 }280 })281 }282 }283 }284 ),285 { wrapper },286 {287 options: { helloWorld: true }288 }289 )290 await waitForValueToChange(() => result.current.isLoading)291 expect(result.current.data.hello).toBe('hello world')292 })293 test('extend actions in return', async () => {294 const { result, waitForValueToChange } = renderHook(295 () => useThing(296 'TActions',297 () => Promise.resolve('hello world'),298 {299 reducer: {300 dictionary: {301 fulfilled: (state, { payload }) => ({302 ...state,303 data: {304 hello: payload305 }306 }),307 additionalAction: state => ({308 ...state,309 data: {310 hello: 'additional action'311 }312 })313 }314 }315 }316 ),317 { wrapper },318 {319 options: { helloWorld: true }320 }321 )322 await waitForValueToChange(() => result.current.isLoading)323 expect(result.current.actions.pending).toBeInstanceOf(Function)324 expect(result.current.actions.fulfilled).toBeInstanceOf(Function)325 expect(result.current.actions.error).toBeInstanceOf(Function)326 expect(result.current.actions.additionalAction).toBeInstanceOf(Function)327 })...

Full Screen

Full Screen

useGameState.spec.ts

Source:useGameState.spec.ts Github

copy

Full Screen

...1415 moves.forEach(async (move) => {16 act(() => result.current.computeMove(move));1718 await waitForValueToChange(() => result.current.nextPlayer);19 });2021 expect(result.current.currentBoard).toEqual([22 "X", "O", "X",23 null, null, null,24 null, null, null25 ]);26 });27 });2829 describe("when the match is restarted", () => {30 const moves = [0, 1, 2, 3, 4, 5];31 let res: RenderResult<UseGameStateResult>;3233 beforeAll(async () => {34 const { result, waitForValueToChange } = renderHook(() => useGameState());35 res = result;3637 moves.forEach(async (move) => {38 act(() => result.current.computeMove(move));3940 await waitForValueToChange(() => result.current.nextPlayer);41 });4243 act(() => result.current.restartGame());44 });4546 it("should reset the board", () => {47 expect(res.current.currentBoard).toEqual([48 null, null, null,49 null, null, null,50 null, null, null51 ]);52 });5354 it("should reset step count", () => {55 expect(res.current.stepNumber).toBe(0);56 });57 });5859 describe('when "X" is the winner', () => {60 const testCases = [61 [[0, 3, 1, 4, 2]],62 [[0, 3, 4, 5, 8]],63 [[6, 1, 7, 2, 8]],64 [[0, 4, 3, 2, 6]],65 [[1, 3, 4, 6, 7]],66 [[2, 0, 5, 1, 8]],67 [[0, 7, 4, 6, 8]],68 [[2, 1, 4, 0, 6]]69 ];7071 it.each(testCases)("with %p moves", (moves) => {72 const { result, waitForValueToChange } = renderHook(() => useGameState());7374 moves.forEach(async (move) => {75 act(() => result.current.computeMove(move));7677 await waitForValueToChange(() => result.current.nextPlayer);78 });7980 expect(result.current.winner).toBe("X");81 });82 });8384 describe('when "O" is the winner', () => {85 const testCases = [86 [[3, 0, 4, 1, 6, 2]],87 [[0, 3, 1, 4, 6, 5]],88 [[0, 6, 1, 7, 3, 8]],89 [[1, 0, 2, 3, 7, 6]],90 [[8, 1, 6, 4, 0, 7]],91 [[0, 2, 1, 5, 4, 8]],92 [[6, 0, 7, 4, 1, 8]],93 [[0, 2, 1, 4, 8, 6]]94 ];9596 it.each(testCases)("with %p moves", (moves) => {97 const { result, waitForValueToChange } = renderHook(() => useGameState());9899 moves.forEach(async (move) => {100 act(() => result.current.computeMove(move));101102 await waitForValueToChange(() => result.current.nextPlayer);103 });104105 expect(result.current.winner).toBe("O");106 });107 });108109 describe("when the match ends in a draw", () => {110 const moves = [2, 1, 4, 6, 5, 8, 7, 3, 0];111112 it(`with ${moves.toString()} moves`, () => {113 const { result, waitForValueToChange } = renderHook(() => useGameState());114115 moves.forEach(async (move) => {116 act(() => result.current.computeMove(move));117118 await waitForValueToChange(() => result.current.nextPlayer);119 });120121 expect(result.current.draw).toBe(true);122 });123 }); ...

Full Screen

Full Screen

useTransactions.test.js

Source:useTransactions.test.js Github

copy

Full Screen

...26 const { result, waitForValueToChange } = renderHook(27 () => useTransactions(),28 { wrapper },29 )30 await waitForValueToChange(() => result.current.data)31 expect(result.current.data).toStrictEqual(getTransactionsReturn)32 expect(mockGetTransactions).toHaveBeenCalledTimes(1)33 })34 it('should post data correctly', async () => {35 const { result, waitForValueToChange } = renderHook(36 () => useTransactions(),37 { wrapper },38 )39 expect(mockPostTransactions).not.toHaveBeenCalled()40 const newTransaction = 241 act(() => {42 result.current.post(newTransaction)43 })44 await waitForValueToChange(() => result.current.data)45 expect(result.current.data).toStrictEqual([46 ...getTransactionsReturn,47 newTransaction,48 ])49 expect(mockPostTransactions).toHaveBeenCalledTimes(1)50 })51 it('should call callback on post', async () => {52 const { result, waitForValueToChange } = renderHook(53 () => useTransactions(),54 { wrapper },55 )56 const newTransaction = 257 const callback = jest.fn()58 expect(callback).not.toHaveBeenCalled()59 act(() => {60 result.current.post(newTransaction, callback)61 })62 await waitForValueToChange(() => result.current.data)63 expect(callback).toHaveBeenCalledTimes(1)64 })...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful