Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
40 views9 pages

Use of Thread - Sleep in Selenium Java

Thread.sleep() is a Java method that pauses the execution of the current thread for a specified time, but it is not recommended for use in Selenium testing due to its time-consuming nature. Testers typically prefer Selenium Waits, such as Explicit Wait, for better efficiency. While Thread.sleep() can be used to validate attribute values, it is not advisable in automated testing code.

Uploaded by

danny111193
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views9 pages

Use of Thread - Sleep in Selenium Java

Thread.sleep() is a Java method that pauses the execution of the current thread for a specified time, but it is not recommended for use in Selenium testing due to its time-consuming nature. Testers typically prefer Selenium Waits, such as Explicit Wait, for better efficiency. While Thread.sleep() can be used to validate attribute values, it is not advisable in automated testing code.

Uploaded by

danny111193
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Use of Thread.

sleep()
in Selenium Java

By,
Saajan Varghese
What is Thread.sleep() ?
In Java, Thread.sleep() is a method that belongs to the Thread class.
• It is used to pause the execution of the current thread for a
specified amount of time.
• The Thread.sleep() method takes a single argument, which is the
number of milliseconds that the thread should sleep. It can be
useful for introducing delays in a program.
• Syntax:

prepared by Saajan Varghese


Understanding of Thread.sleep() in Selenium
• Usually Testers will not use Thread.sleep() while
automating or testing as it simply waits till the mentioned
milliseconds.
• It’s a Java command, not a Selenium command.
• Time consuming.
• Instead, they use Selenium Waits.

prepared by Saajan Varghese


we can use
In

prepared by Saajan Varghese


For Example, In this Web Application we want to test
the value attribute

Click on to view the image dynamically

prepared by Saajan Varghese


Understanding of Thread.sleep() in Selenium Java
• We can use Explicit Wait to Test the attribute value.
• But we can also use Thread.sleep() to test the attribute value.
• To my understanding, after sending the keys, Explicit wait takes
one second to validate the value. Mentioning Thread.sleep(1000);
makes no difference.
• Not Recommended to Use Thread.sleep() in Code. I am saying by
Thread.sleep() also we can validate.

prepared by Saajan Varghese


Use of Thread.sleep() in Selenium Java
• Here’s the Test Code to Validate attribute value

prepared by Saajan Varghese


Test Result of the Code:

prepared by Saajan Varghese


Thanks for Reading

By,
Saajan Varghese

You might also like