SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
Selenium using Waits
Test automation basics with Selenium & Java
Waits VS sleeps
● Thread.sleep(1000) - stops program execution to 1 second
● WebDriverWait waits for some event
Selenium waits
● Implicit wait
● Explicit wait
● Fluent wait
Implicit wait
- waits till element will be displayed on a page
- waits till timeout
- if element was not found, it throws:
org.openqa.selenium.NoSuchElementException:
no such element
Example:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Now, this form is deprecated, so use it as follows:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
Explicit wait
1) customizable timeout
2) flexible wait for events:
● element's presence
● element (in-)visibility
● till page loaded
● till alert displayed
● till Javascript returns some value
Example:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.elementToBeClickable(searchButton));
Do not mix implicit and explicit waits
if you use explicit waits,
then implicit wait should not be used be or set to ‘0’
● implicit wait equals 0 by default,
● it could be set to zero manually:
Implicit and explicit waits
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
Custom wait example
boolean isElementDisplayed(By by, int timeout) throws InterruptedException {
List<WebElement> elements = driver.findElements(by);
for(int i = 0; (i < timeout) && (elements.size() == 0); i++) {
Thread.sleep(1000);
elements = driver.findElements(by);
}
return elements.size() > 0;
}
Add to test explicit wait,
until chosen element
would not be visible.
Create test with following steps:
- Open google.com
- wait until page header will be visible
- wait until search button will be clickable
- type some string in search field
- press search button
- verify that search page header is invisible on
results page
Hint: use
ExpectedConditions.invisibilityOf(element));
Exercise

Contenu connexe

Similaire à waits.pdf

Moving from selenium to protractor for test automation
Moving from selenium to protractor for test automationMoving from selenium to protractor for test automation
Moving from selenium to protractor for test automationZoe Gilbert
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with exampleshadabgilani
 
Advanced Selenium Workshop
Advanced Selenium WorkshopAdvanced Selenium Workshop
Advanced Selenium WorkshopClever Moe
 
Synchronization in Selenium WebDriver
Synchronization in Selenium WebDriverSynchronization in Selenium WebDriver
Synchronization in Selenium WebDriverSHUBHAM PATIL
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsМарія Русин
 
Protractor End To End Testing For AngularJS
Protractor End To End Testing For AngularJSProtractor End To End Testing For AngularJS
Protractor End To End Testing For AngularJSKnoldus Inc.
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instrumentsArtem Nagornyi
 
Forge - DevCon 2016: Building a Drone Imagery Service
Forge - DevCon 2016: Building a Drone Imagery ServiceForge - DevCon 2016: Building a Drone Imagery Service
Forge - DevCon 2016: Building a Drone Imagery ServiceAutodesk
 
Service workers
Service workersService workers
Service workersjungkees
 
Service Worker Presentation
Service Worker PresentationService Worker Presentation
Service Worker PresentationKyle Dorman
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIVisual Engineering
 
Waits alerts and switch windows
Waits alerts and switch windowsWaits alerts and switch windows
Waits alerts and switch windowsDucat
 

Similaire à waits.pdf (20)

Automated testing by Richard Olrichs and Wilfred vd Deijl
Automated testing by Richard Olrichs and Wilfred vd DeijlAutomated testing by Richard Olrichs and Wilfred vd Deijl
Automated testing by Richard Olrichs and Wilfred vd Deijl
 
Moving from selenium to protractor for test automation
Moving from selenium to protractor for test automationMoving from selenium to protractor for test automation
Moving from selenium to protractor for test automation
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
 
Responsive interfaces
Responsive interfacesResponsive interfaces
Responsive interfaces
 
Advanced Selenium Workshop
Advanced Selenium WorkshopAdvanced Selenium Workshop
Advanced Selenium Workshop
 
Synchronization in Selenium WebDriver
Synchronization in Selenium WebDriverSynchronization in Selenium WebDriver
Synchronization in Selenium WebDriver
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax Applications
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
Protractor End To End Testing For AngularJS
Protractor End To End Testing For AngularJSProtractor End To End Testing For AngularJS
Protractor End To End Testing For AngularJS
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
Forge - DevCon 2016: Building a Drone Imagery Service
Forge - DevCon 2016: Building a Drone Imagery ServiceForge - DevCon 2016: Building a Drone Imagery Service
Forge - DevCon 2016: Building a Drone Imagery Service
 
Service workers
Service workersService workers
Service workers
 
Life Cycle hooks in VueJs
Life Cycle hooks in VueJsLife Cycle hooks in VueJs
Life Cycle hooks in VueJs
 
Advanced android app development
Advanced android app developmentAdvanced android app development
Advanced android app development
 
WebDriver Waits
WebDriver WaitsWebDriver Waits
WebDriver Waits
 
Service Worker Presentation
Service Worker PresentationService Worker Presentation
Service Worker Presentation
 
Selenium
SeleniumSelenium
Selenium
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Waits alerts and switch windows
Waits alerts and switch windowsWaits alerts and switch windows
Waits alerts and switch windows
 

Plus de ssuser0562f1

Алгоритмизация и программирование С/С++
Алгоритмизация и  программирование С/С++Алгоритмизация и  программирование С/С++
Алгоритмизация и программирование С/С++ssuser0562f1
 
Algorithms and programming lecture in ru
Algorithms and programming lecture in ruAlgorithms and programming lecture in ru
Algorithms and programming lecture in russuser0562f1
 
Geometry algorithms and formulas calculation
Geometry algorithms and formulas calculationGeometry algorithms and formulas calculation
Geometry algorithms and formulas calculationssuser0562f1
 
Algorithms in number theory presentation
Algorithms in number theory presentationAlgorithms in number theory presentation
Algorithms in number theory presentationssuser0562f1
 
Курсовая (1).pdf
Курсовая (1).pdfКурсовая (1).pdf
Курсовая (1).pdfssuser0562f1
 
springdatajpatwjug-120527215242-phpapp02.pdf
springdatajpatwjug-120527215242-phpapp02.pdfspringdatajpatwjug-120527215242-phpapp02.pdf
springdatajpatwjug-120527215242-phpapp02.pdfssuser0562f1
 
springdatajpa-up.pdf
springdatajpa-up.pdfspringdatajpa-up.pdf
springdatajpa-up.pdfssuser0562f1
 
08-170327133157.pdf
08-170327133157.pdf08-170327133157.pdf
08-170327133157.pdfssuser0562f1
 

Plus de ssuser0562f1 (14)

Алгоритмизация и программирование С/С++
Алгоритмизация и  программирование С/С++Алгоритмизация и  программирование С/С++
Алгоритмизация и программирование С/С++
 
Algorithms and programming lecture in ru
Algorithms and programming lecture in ruAlgorithms and programming lecture in ru
Algorithms and programming lecture in ru
 
Geometry algorithms and formulas calculation
Geometry algorithms and formulas calculationGeometry algorithms and formulas calculation
Geometry algorithms and formulas calculation
 
Algorithms in number theory presentation
Algorithms in number theory presentationAlgorithms in number theory presentation
Algorithms in number theory presentation
 
jpa_nus.pdf
jpa_nus.pdfjpa_nus.pdf
jpa_nus.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
servlets1.pdf
servlets1.pdfservlets1.pdf
servlets1.pdf
 
servlets.pdf
servlets.pdfservlets.pdf
servlets.pdf
 
Курсовая (1).pdf
Курсовая (1).pdfКурсовая (1).pdf
Курсовая (1).pdf
 
springdatajpatwjug-120527215242-phpapp02.pdf
springdatajpatwjug-120527215242-phpapp02.pdfspringdatajpatwjug-120527215242-phpapp02.pdf
springdatajpatwjug-120527215242-phpapp02.pdf
 
springdatajpa-up.pdf
springdatajpa-up.pdfspringdatajpa-up.pdf
springdatajpa-up.pdf
 
08-170327133157.pdf
08-170327133157.pdf08-170327133157.pdf
08-170327133157.pdf
 
waits.pdf
waits.pdfwaits.pdf
waits.pdf
 
geometry.pdf
geometry.pdfgeometry.pdf
geometry.pdf
 

Dernier

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 

Dernier (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 

waits.pdf

  • 1. Selenium using Waits Test automation basics with Selenium & Java
  • 2. Waits VS sleeps ● Thread.sleep(1000) - stops program execution to 1 second ● WebDriverWait waits for some event
  • 3. Selenium waits ● Implicit wait ● Explicit wait ● Fluent wait
  • 4. Implicit wait - waits till element will be displayed on a page - waits till timeout - if element was not found, it throws: org.openqa.selenium.NoSuchElementException: no such element Example: driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); Now, this form is deprecated, so use it as follows: driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
  • 5. Explicit wait 1) customizable timeout 2) flexible wait for events: ● element's presence ● element (in-)visibility ● till page loaded ● till alert displayed ● till Javascript returns some value Example: WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); wait.until(ExpectedConditions.elementToBeClickable(searchButton));
  • 6. Do not mix implicit and explicit waits if you use explicit waits, then implicit wait should not be used be or set to ‘0’ ● implicit wait equals 0 by default, ● it could be set to zero manually: Implicit and explicit waits driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
  • 7. Custom wait example boolean isElementDisplayed(By by, int timeout) throws InterruptedException { List<WebElement> elements = driver.findElements(by); for(int i = 0; (i < timeout) && (elements.size() == 0); i++) { Thread.sleep(1000); elements = driver.findElements(by); } return elements.size() > 0; }
  • 8. Add to test explicit wait, until chosen element would not be visible. Create test with following steps: - Open google.com - wait until page header will be visible - wait until search button will be clickable - type some string in search field - press search button - verify that search page header is invisible on results page Hint: use ExpectedConditions.invisibilityOf(element)); Exercise