xctest - How to Wait for an element and do not fail if not found after a certain time xcuitest -


in application have 2 tab buttons tasks , worklist. tasks loaded. worklist button dynamic , loaded after time.

i want click tasks button after time. ie, need wait worklist button , if exists after time click tasks button. if timeout exceeds , worklist button not loaded need click tasks button.

i cannot use sleep.

can use expectationforpredicate , waitforexpectationswithtimeout. waitforexpectationswithtimeout gets failed if element not found after timeout. if write

waitforexpectationswithtimeout(120) { (error) -> void in          click tasks button } 

this gives stall on main thread.

i want click tasks button after worklists loaded. if worklist not loaded after timeout, need click tasks button..

is there solution. help.

you can create own custom method handle this:

func waitforelementtoexist(     element: xcuielement,     timeout: int = 20,     failtestonfailure: bool = true)     -> bool {     var = 0     let message = "timed out while waiting element: \(element) after \(timeout) seconds"      while !element.exists {         sleep(1)         += 1          guard < timeout else {             if failtestonfailure {                 xctfail(message)             } else {                 print(message)             }              return false         }     }      return true } 

you can call method like:

if waitforelementtoexist(taskbutton, timeout: 20, failtestonfailure: false) {     button.tap() } 

hope works you!


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -