How long it takes to switch on NFC through Appium?

I am running my appium tests in which I need to switch the NFC ON for some time and then switch OFF.

I have put the hard wait of 5 seconds.

I am currently optimizing the time and hence would like to know the exact time taken by NFC to switch on. Can you please help me on this.

Thanks.

The time will always vary, especially if you ever want to run your tests on different devices and/or os’s. Read up on implicit waits and make your life a whole lot easier:

http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

I am not sure how can we manage NFC switch ON and OFF using implicit or explicit wait.

Sorry I thought you were trying to optimize the time.

Ok, actually I have kept proper waits whenever it’s necessary, but in case of switching ON and OFF NFC, switching OFF and ON Data connection, switch ON and OFF Airplane mode doesn’t seem to be consistent throughout the devices in terms of time.

I feel like we aren’t communicating very well. It’s probably my fault.

However, I can’t help but give it one more try. If your times are inconsistent, this is what implicit waits are for. You put the maximum time, say 5 seconds, and during the implicit wait you get constant polling so let’s say on one device it only takes 3 seconds–well, with an implicit wait set for 5 seconds the operation only takes 3 seconds. Another device only takes 1 second–so in that case with an implicit wait of 5 seconds it only takes 1 second. In another case it takes the full 5 seconds–with an implicit wait of 5 seconds it takes 5 seconds.

It seems to me that implicit waits are tailor made for your situation–yet you disagree. I’m either not being clear or not understanding your problem. I’ll try not to waste your time anymore.

I understand your quote fully.[quote=“wreed, post:6, topic:13898”]
If your times are inconsistent, this is what implicit waits are for.
[/quote], but this will not help in case of switching OFF and ON NFC, since that process happens in background. I am not able to find any solution by which we can check whether the NFC is set true after specific time or not. Your quote is applicable when we search for an element and wait for it… Do you know anything similar which can check NFC status periodically by polling, let know.

Many thanks.

I have no idea how you are currently turning off/on NFC or how you are checking the status since you never state this in the OP or in subsequent posts. Were I to do this I would make a system call to adb shell dumpsys nfc and I’d surround that in an implicit wait.