Thread.Sleep in Java
Now a days if we want our execution to be halted for sometimes [mainly observed in Automation Testing when a page needs to be loaded first and then some line of code will be executed], We use Thread.sleep(int Sec) method. Well this is quite recognized/common method to solve if we want my program to wait for specific point of time.More details can be found here in java doc.
As per java doc..
Notice that main declares that it throws InterruptedException. This is an exception that sleep throws when another thread interrupts the current thread while sleep is active. Since this application has not defined another thread to cause the interrupt, it doesn’t bother to catch InterruptedException.
But now a days I have seen that it is a requirement to do more customization regarding the same.
One approach can be –[taken from stackoverflow]
public static void pause(int seconds){
Date start = new Date();
Date end = new Date();
while(end.getTime() - start.getTime() < seconds * 1000){
end = new Date();
}
}
Another Approach can be to use.
Pause.pause(int sec)
The third approach can be..
public static void wait_for_element(){
do
{
pause(2);//use the first approach for implementing this pause method
}
until(driver.findElements(By.xpath("//*[starts-with(@id,'frm')]")).get(1).isDisplayed())
//the element is displayed
Thread.Sleep in Java
Now the choice is yours …depending on the scenario, you can take any one of the process. Happy testing.
Feelings were great to visit dis….. Bt thr is a problem at d tym of subscription (smthng email problem).
Hello Abhranil,
you can join via this link-https://feedburner.google.com/fb/a/mailverify?uri=TechTravelHub
Regards,
Animesh
My brother recommended I may like this website. He was entirely right.
This post actually made my day. You can not
consider just how so much time I had spent for this information! Thank you!
What’s up all, here every one is sharing such familiarity, thus
it’s fastidious to read this webpage, and I used to go to
see this weblog all the time.
Thanks for sharing your thoughts on Computers. Regards
Wow, this piece of writing is fastidious, my younger sister is analyzing these kinds of things,
therefore I am going to let know her.
I don’t even know how I ended up here, but I thought this post was great.
I do not know who you are but definitely you’re going to a famous blogger
if you aren’t already 😉 Cheers!
This is a topic which is near to my heart… Many thanks! Where are your contact details though?
What’s up, after reading this amazing post i am also happy to share my know-how here with
friends.