| Line 164... |
Line 164... |
| 164 |
actionProvider.moveByOffset(moveByOffset, 0).perform();
|
164 |
actionProvider.moveByOffset(moveByOffset, 0).perform();
|
| 165 |
refine(driver, actionProvider, cal[1]);
|
165 |
refine(driver, actionProvider, cal[1]);
|
| 166 |
actionProvider.release().perform();
|
166 |
actionProvider.release().perform();
|
| 167 |
LOGGER.info("Move click performed (main {}px)", moveByOffset);
|
167 |
LOGGER.info("Move click performed (main {}px)", moveByOffset);
|
| 168 |
try {
|
168 |
try {
|
| - |
|
169 |
// Success used to mean "the dx_captcha_basic_bar-inform error element
|
| - |
|
170 |
// did not appear". realme rebuilt this page, so that element may no
|
| - |
|
171 |
// longer exist -- in which case the wait always times out and EVERY
|
| - |
|
172 |
// attempt reports success while the captcha was never solved. That is
|
| - |
|
173 |
// exactly what happened: 27 successes, 27 missed responses, 0 rows.
|
| 169 |
try {
|
174 |
//
|
| 170 |
wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
|
175 |
// The lookup response arriving is the only signal that actually proves
|
| - |
|
176 |
// the captcha passed, so wait for that instead.
|
| - |
|
177 |
String json = awaitResponse(driver, 8000);
|
| - |
|
178 |
if (json == null) {
|
| 171 |
LOGGER.warn("Failed = " + counter);
|
179 |
LOGGER.warn("Failed = " + counter);
|
| 172 |
} catch (Exception notFailedException) {
|
180 |
} else {
|
| 173 |
LOGGER.info("Success at attempt " + counter);
|
181 |
LOGGER.info("Success at attempt " + counter);
|
| 174 |
//List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
|
182 |
//List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
|
| 175 |
//WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5') or contains(text(), 'Non-Activate')]"));
|
183 |
//WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5') or contains(text(), 'Non-Activate')]"));
|
| 176 |
// Read the JSON the page already received. The old locator
|
184 |
// Read the JSON the page already received. The old locator
|
| 177 |
// keyed off a label that no longer exists, and its "| //h1" branch
|
185 |
// keyed off a label that no longer exists, and its "| //h1" branch
|
| 178 |
// would silently grab a page heading and try to parse it as a date.
|
186 |
// would silently grab a page heading and try to parse it as a date.
|
| 179 |
// The API is explicit: expiryDate (yyyy.MM.dd) plus an isActivation
|
187 |
// The API is explicit: expiryDate (yyyy.MM.dd) plus an isActivation
|
| 180 |
// flag, so nothing has to be inferred from message text.
|
188 |
// flag, so nothing has to be inferred from message text.
|
| 181 |
String json = capturedResponse(driver);
|
- |
|
| 182 |
LocalDate activationDate = activationFrom(json);
|
189 |
LocalDate activationDate = activationFrom(json);
|
| 183 |
|
- |
|
| 184 |
if (json == null) {
|
- |
|
| 185 |
LOGGER.warn("Result shown but no active/check response captured for imei {}", imei);
|
- |
|
| 186 |
} else {
|
- |
|
| 187 |
LOGGER.info("Activation lookup for {} -> {}", imei,
|
190 |
LOGGER.info("Activation lookup for {} -> {}", imei,
|
| 188 |
activationDate != null ? activationDate : "not activated");
|
191 |
activationDate != null ? activationDate : "not activated");
|
| 189 |
}
|
- |
|
| 190 |
// Always record, even with a null date. findElement used to THROW
|
192 |
// Always record, even with a null date. findElement used to THROW
|
| 191 |
// when the element was missing, so nothing was written and the imei
|
193 |
// when the element was missing, so nothing was written and the imei
|
| 192 |
// came back on every run indefinitely.
|
194 |
// came back on every run indefinitely.
|
| 193 |
dateMap.put(imei, activationDate);
|
195 |
dateMap.put(imei, activationDate);
|
| 194 |
clearCapture(driver);
|
196 |
clearCapture(driver);
|
| Line 295... |
Line 297... |
| 295 |
} catch (Exception e) {
|
297 |
} catch (Exception e) {
|
| 296 |
LOGGER.warn("Could not install the response capture hook: " + e.getMessage());
|
298 |
LOGGER.warn("Could not install the response capture hook: " + e.getMessage());
|
| 297 |
}
|
299 |
}
|
| 298 |
}
|
300 |
}
|
| 299 |
|
301 |
|
| - |
|
302 |
/**
|
| - |
|
303 |
* Wait for the lookup response to arrive, which is the only reliable proof that
|
| - |
|
304 |
* the captcha was actually solved. Polls rather than blocking so a solved captcha
|
| - |
|
305 |
* is picked up as soon as the request completes.
|
| - |
|
306 |
*/
|
| - |
|
307 |
private String awaitResponse(WebDriver driver, long timeoutMs) {
|
| - |
|
308 |
long deadline = System.currentTimeMillis() + timeoutMs;
|
| - |
|
309 |
while (System.currentTimeMillis() < deadline) {
|
| - |
|
310 |
String json = capturedResponse(driver);
|
| - |
|
311 |
if (json != null && !json.trim().isEmpty()) return json;
|
| - |
|
312 |
try {
|
| - |
|
313 |
Thread.sleep(300);
|
| - |
|
314 |
} catch (InterruptedException ie) {
|
| - |
|
315 |
Thread.currentThread().interrupt();
|
| - |
|
316 |
return null;
|
| - |
|
317 |
}
|
| - |
|
318 |
}
|
| - |
|
319 |
return null;
|
| - |
|
320 |
}
|
| - |
|
321 |
|
| 300 |
private String capturedResponse(WebDriver driver) {
|
322 |
private String capturedResponse(WebDriver driver) {
|
| 301 |
try {
|
323 |
try {
|
| 302 |
Object v = ((JavascriptExecutor) driver).executeScript("return window.__rmResp || null;");
|
324 |
Object v = ((JavascriptExecutor) driver).executeScript("return window.__rmResp || null;");
|
| 303 |
return v == null ? null : v.toString();
|
325 |
return v == null ? null : v.toString();
|
| 304 |
} catch (Exception e) {
|
326 |
} catch (Exception e) {
|