Subversion Repositories SmartDukaan

Rev

Rev 37428 | Rev 37431 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37428 Rev 37429
Line 162... Line 162...
162
                                            // rendered text. The DOM value is built from two text nodes -- the
162
                                            // rendered text. The DOM value is built from two text nodes -- the
163
                                            // date plus a "(UTC+x)" suffix derived from the browser timezone --
163
                                            // date plus a "(UTC+x)" suffix derived from the browser timezone --
164
                                            // and the old locator tested only the first, so it matched nothing.
164
                                            // and the old locator tested only the first, so it matched nothing.
165
                                            // The API carries regDate as epoch millis, which has no format or
165
                                            // The API carries regDate as epoch millis, which has no format or
166
                                            // timezone ambiguity at all.
166
                                            // timezone ambiguity at all.
167
                                            String json = capturedResponse(driver);
167
                                            String json = awaitResponse(driver, 8000);
168
                                            LocalDate activationDate = regDateFrom(json);
168
                                            LocalDate activationDate = regDateFrom(json);
169
 
169
 
170
                                            if (json == null) {
170
                                            if (json == null) {
171
                                                LOGGER.warn("Result shown but no getDeviceInfo response captured for imei {}", imei);
171
                                                LOGGER.warn("No getDeviceInfo response for imei {} (captcha said: {})",
-
 
172
                                                        imei, captchaSignal(driver));
172
                                            } else {
173
                                            } else {
173
                                                LOGGER.info("Activation lookup for {} -> {}", imei,
174
                                                LOGGER.info("Activation lookup for {} -> {}", imei,
174
                                                        activationDate != null ? activationDate : "no activation date");
175
                                                        activationDate != null ? activationDate : "no activation date");
175
                                            }
176
                                            }
176
                                            // Always record the imei, even with a null date: findElement used to
177
                                            // Always record the imei, even with a null date: findElement used to
Line 264... Line 265...
264
        } catch (Exception e) {
265
        } catch (Exception e) {
265
            return null;
266
            return null;
266
        }
267
        }
267
    }
268
    }
268
 
269
 
-
 
270
    /** Poll for the response instead of reading once: the success signal can fire
-
 
271
     *  before the lookup request has completed, which loses the payload. */
-
 
272
    private String awaitResponse(WebDriver driver, long timeoutMs) {
-
 
273
        long deadline = System.currentTimeMillis() + timeoutMs;
-
 
274
        while (System.currentTimeMillis() < deadline) {
-
 
275
            String json = capturedResponse(driver);
-
 
276
            if (json != null && !json.trim().isEmpty()) return json;
-
 
277
            try {
-
 
278
                Thread.sleep(300);
-
 
279
            } catch (InterruptedException ie) {
-
 
280
                Thread.currentThread().interrupt();
-
 
281
                return null;
-
 
282
            }
-
 
283
        }
-
 
284
        return null;
-
 
285
    }
-
 
286
 
269
    private String capturedResponse(WebDriver driver) {
287
    private String capturedResponse(WebDriver driver) {
270
        try {
288
        try {
271
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__oppoResp || null;");
289
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__oppoResp || null;");
272
            return v == null ? null : v.toString();
290
            return v == null ? null : v.toString();
273
        } catch (Exception e) {
291
        } catch (Exception e) {