Subversion Repositories SmartDukaan

Rev

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

Rev 37426 Rev 37428
Line 174... Line 174...
174
                                        //
174
                                        //
175
                                        // The lookup response arriving is the only signal that actually proves
175
                                        // The lookup response arriving is the only signal that actually proves
176
                                        // the captcha passed, so wait for that instead.
176
                                        // the captcha passed, so wait for that instead.
177
                                        String json = awaitResponse(driver, 8000);
177
                                        String json = awaitResponse(driver, 8000);
178
                                        if (json == null) {
178
                                        if (json == null) {
179
                                            LOGGER.warn("Failed = " + counter);
179
                                            LOGGER.warn("Failed = {} (captcha said: {})",
-
 
180
                                                    counter, captchaSignal(driver));
180
                                        } else {
181
                                        } else {
181
                                            LOGGER.info("Success  at attempt " + counter);
182
                                            LOGGER.info("Success  at attempt " + counter);
182
                                            //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
183
                                            //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
183
                                            //WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
184
                                            //WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
184
                                            // Read the JSON the page already received. The old locator
185
                                            // Read the JSON the page already received. The old locator
Line 272... Line 273...
272
    /** Stash the active/check response on window as the page receives it. */
273
    /** Stash the active/check response on window as the page receives it. */
273
    private void installResponseCapture(WebDriver driver) {
274
    private void installResponseCapture(WebDriver driver) {
274
        try {
275
        try {
275
            ((JavascriptExecutor) driver).executeScript(
276
            ((JavascriptExecutor) driver).executeScript(
276
                "if (!window.__rmCapInstalled) {"
277
                "if (!window.__rmCapInstalled) {"
277
              + "  window.__rmCapInstalled = true; window.__rmResp = null;"
278
              + "  window.__rmCapInstalled = true; window.__rmResp = null; window.__rmCaptcha = null;"
278
              // axios can sit on either transport, and realme's page uses fetch --
279
              // axios can sit on either transport, and realme's page uses fetch --
279
              // an XHR-only hook silently captures nothing, which is exactly what
280
              // an XHR-only hook silently captures nothing, which is exactly what
280
              // 'no active/check response captured' was reporting.
281
              // 'no active/check response captured' was reporting.
281
              + "  var O = XMLHttpRequest.prototype.open;"
282
              + "  var O = XMLHttpRequest.prototype.open;"
282
              + "  XMLHttpRequest.prototype.open = function(m,u){"
283
              + "  XMLHttpRequest.prototype.open = function(m,u){"
283
              + "    this.addEventListener('load', function(){"
284
              + "    this.addEventListener('load', function(){"
-
 
285
              + "      try { var s=String(u);"
284
              + "      try { if (String(u).indexOf('active/check') !== -1) window.__rmResp = this.responseText; } catch(e){}"
286
              + "        if (s.indexOf('active/check') !== -1) window.__rmResp = this.responseText;"
-
 
287
              + "        else if (s.indexOf('captcha') !== -1) window.__rmCaptcha = s + ' -> ' + (this.responseText||'').slice(0,200);"
-
 
288
              + "      } catch(e){}"
285
              + "    });"
289
              + "    });"
286
              + "    return O.apply(this, arguments);"
290
              + "    return O.apply(this, arguments);"
287
              + "  };"
291
              + "  };"
288
              + "  var F = window.fetch;"
292
              + "  var F = window.fetch;"
289
              + "  if (F) { window.fetch = function(){"
293
              + "  if (F) { window.fetch = function(){"
Line 317... Line 321...
317
            }
321
            }
318
        }
322
        }
319
        return null;
323
        return null;
320
    }
324
    }
321
 
325
 
-
 
326
    /** Last response from the captcha widget itself -- says WHY a drag was refused. */
-
 
327
    private String captchaSignal(WebDriver driver) {
-
 
328
        try {
-
 
329
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__rmCaptcha || null;");
-
 
330
            return v == null ? null : v.toString();
-
 
331
        } catch (Exception e) {
-
 
332
            return null;
-
 
333
        }
-
 
334
    }
-
 
335
 
322
    private String capturedResponse(WebDriver driver) {
336
    private String capturedResponse(WebDriver driver) {
323
        try {
337
        try {
324
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__rmResp || null;");
338
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__rmResp || null;");
325
            return v == null ? null : v.toString();
339
            return v == null ? null : v.toString();
326
        } catch (Exception e) {
340
        } catch (Exception e) {