Skip to content

Commit a396715

Browse files
Set page load strategy to none + retries
1 parent 7d17ba6 commit a396715

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/kotlin/com/stefanbratanov/sofiasupermarketsapi/brochure/FantasticoBrochureDownloader.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import java.time.Duration
1414
import java.time.LocalDate
1515
import java.time.format.DateTimeFormatter.ofPattern
1616
import java.util.concurrent.TimeUnit
17+
import java.util.concurrent.TimeoutException
1718
import kotlin.text.RegexOption.IGNORE_CASE
1819
import org.openqa.selenium.By
20+
import org.openqa.selenium.PageLoadStrategy
1921
import org.openqa.selenium.chrome.ChromeDriver
2022
import org.openqa.selenium.chrome.ChromeOptions
2123
import org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable
@@ -39,6 +41,7 @@ class FantasticoBrochureDownloader(@Value("\${fantastico.url}") private val url:
3941
options.addArguments("--window-size=1920,1200")
4042
options.addArguments("--no-sandbox")
4143
options.addArguments("--disable-dev-shm-usage")
44+
options.setPageLoadStrategy(PageLoadStrategy.NONE)
4245
}
4346
}
4447

@@ -52,7 +55,7 @@ class FantasticoBrochureDownloader(@Value("\${fantastico.url}") private val url:
5255

5356
val driver = ChromeDriver(options)
5457

55-
val waitDriver = WebDriverWait(driver, Duration.ofSeconds(10))
58+
val waitDriver = WebDriverWait(driver, Duration.ofSeconds(30))
5659

5760
val brochures =
5861
htmlDoc
@@ -77,7 +80,13 @@ class FantasticoBrochureDownloader(@Value("\${fantastico.url}") private val url:
7780
val flippingBookUrl = it.attr("data-url")
7881

7982
// loading the flipping book
80-
driver.get(flippingBookUrl)
83+
repeat(3) {
84+
try {
85+
driver.get(flippingBookUrl)
86+
} catch (_: TimeoutException) {
87+
log.warn("Retrying loading flipping book due to timeout...")
88+
}
89+
}
8190

8291
val downloadSelector =
8392
By.cssSelector("a[aria-label=\"Download the flipbook as a PDF file\"]")

0 commit comments

Comments
 (0)