Subversion Repositories SmartDukaan

Rev

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

Rev 36583 Rev 37410
Line 92... Line 92...
92
                }
92
                }
93
 
93
 
94
                for (int i = 0; i < remainingImeis.size(); i++) {
94
                for (int i = 0; i < remainingImeis.size(); i++) {
95
                    String imei = remainingImeis.get(i);
95
                    String imei = remainingImeis.get(i);
96
                    try {
96
                    try {
97
                        System.out.println("Starting fresh with new IMEI " + imei);
97
                        LOGGER.info("Starting fresh with new IMEI " + imei);
98
                        if (driver.findElement(By.className("el-input__inner")).getAttribute("value").length() > 0) {
98
                        if (driver.findElement(By.className("el-input__inner")).getAttribute("value").length() > 0) {
99
                            System.out.println("Darn.. leaving" + driver.findElement(By.className("el-input__inner")).getAttribute("value"));
99
                            LOGGER.info("Darn.. leaving" + driver.findElement(By.className("el-input__inner")).getAttribute("value"));
100
                            driver.get("https://support.oppo.com/in/warranty-check/");
100
                            driver.get("https://support.oppo.com/in/warranty-check/");
101
                            break;
101
                            break;
102
                        }
102
                        }
103
                        driver.findElement(By.className("el-input__inner")).sendKeys(imei);
103
                        driver.findElement(By.className("el-input__inner")).sendKeys(imei);
104
 
104
 
Line 109... Line 109...
109
                        int counter = 1;
109
                        int counter = 1;
110
                        boolean captchaNotBroken = true;
110
                        boolean captchaNotBroken = true;
111
                        do {
111
                        do {
112
                            String fileName = "/tmp/oppo-simple-i-" + counter + " " + System.currentTimeMillis() + ".png";
112
                            String fileName = "/tmp/oppo-simple-i-" + counter + " " + System.currentTimeMillis() + ".png";
113
                            try {
113
                            try {
114
                                System.out.println("Starting Do");
114
                                LOGGER.info("Starting Do");
115
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
115
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
116
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
116
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
117
                                slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
117
                                slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
118
                                //System.out.println("Slide button - " + slideButton);
118
                                //System.out.println("Slide button - " + slideButton);
119
                                System.out.println("Margin Left before- " + slideButton.getCssValue("margin-left"));
119
                                LOGGER.info("Margin Left before- " + slideButton.getCssValue("margin-left"));
120
                                actionProvider.moveToElement(slideButton).clickAndHold()
120
                                actionProvider.moveToElement(slideButton).clickAndHold()
121
                                        .moveByOffset(1, 0)//.pause(2000)
121
                                        .moveByOffset(1, 0)//.pause(2000)
122
                                        .perform();
122
                                        .perform();
123
 
123
 
124
                                //actionProvider.moveByOffset(-1,0).pause(2000).perform();
124
                                //actionProvider.moveByOffset(-1,0).pause(2000).perform();
125
                                System.out.println("Margin Left after - " + slideButton.getCssValue("margin-left"));
125
                                LOGGER.info("Margin Left after - " + slideButton.getCssValue("margin-left"));
126
                                //Thread.sleep(5000);
126
                                //Thread.sleep(5000);
127
                            } catch (Exception e) {
127
                            } catch (Exception e) {
-
 
128
                                LOGGER.warn("Slider captcha widget (dx_captcha_basic_*) not found or not draggable"
128
                                System.out.println(e.getMessage());
129
                                        + " - reloading. Cause: " + e.getMessage());
129
                                driver.get("https://support.oppo.com/in/warranty-check/");
130
                                driver.get("https://support.oppo.com/in/warranty-check/");
130
                                break;
131
                                break;
131
                            }
132
                            }
132
                            double[] circles = getMatCircles2(driver, fileName);
133
                            double[] circles = getMatCircles2(driver, fileName);
133
                            if (circles != null) {
134
                            if (circles != null) {
134
                                double firstCircleX = circles[0];
135
                                double firstCircleX = circles[0];
135
                                double secondCircleX = circles[1];
136
                                double secondCircleX = circles[1];
136
                                double distance = Math.abs(firstCircleX - secondCircleX);
137
                                double distance = Math.abs(firstCircleX - secondCircleX);
137
                                System.out.println("Distance is " + distance);
138
                                LOGGER.info("Distance is " + distance);
138
 
139
 
139
                                System.out.println("Starting Checkdistance method");
140
                                LOGGER.info("Starting Checkdistance method");
140
                                int moveByOffset = checkDistance(driver, wait10Sec, actionProvider, distance, slideButton);
141
                                int moveByOffset = checkDistance(driver, wait10Sec, actionProvider, distance, slideButton);
141
                                if (moveByOffset > 0) {
142
                                if (moveByOffset > 0) {
142
                                    System.out.println("Margin Offset - " + slideButton.getCssValue("margin-left"));
143
                                    LOGGER.info("Margin Offset - " + slideButton.getCssValue("margin-left"));
143
                                    System.out.println("Ending Checkdistance method " + moveByOffset);
144
                                    LOGGER.info("Ending Checkdistance method " + moveByOffset);
144
                                    actionProvider.moveByOffset(moveByOffset, 0).release().perform();
145
                                    actionProvider.moveByOffset(moveByOffset, 0).release().perform();
145
                                    System.out.println("Move click performed");
146
                                    LOGGER.info("Move click performed");
146
                                    try {
147
                                    try {
147
                                        try {
148
                                        try {
148
                                            wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
149
                                            wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
149
                                            System.out.println("Failed = " + counter);
150
                                            LOGGER.warn("Failed = " + counter);
150
                                        } catch (Exception notFailedException) {
151
                                        } catch (Exception notFailedException) {
151
                                            System.out.println("Success  at attempt " + counter);
152
                                            LOGGER.info("Success  at attempt " + counter);
152
                                            //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
153
                                            //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
153
                                            WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
154
                                            WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
154
                                            //TODO: IF not found activationElement
155
                                            //TODO: IF not found activationElement
155
                                            if (activationTimeElement != null) {
156
                                            if (activationTimeElement != null) {
156
                                                String activationDateString = activationTimeElement.getText().trim();
157
                                                String activationDateString = activationTimeElement.getText().trim();
157
                                                System.out.println("Date --  " + activationDateString);
158
                                                LOGGER.info("Date --  " + activationDateString);
158
                                                try {
159
                                                try {
159
                                                    dateMap.put(imei, LocalDate.parse(activationDateString.split(" ")[0], DateTimeFormatter.ofPattern("dd/MM/yyyy")));
160
                                                    dateMap.put(imei, LocalDate.parse(activationDateString.split(" ")[0], DateTimeFormatter.ofPattern("dd/MM/yyyy")));
160
                                                    System.out.println("Date --  " + activationDateString);
161
                                                    LOGGER.info("Date --  " + activationDateString);
161
                                                } catch (Exception e) {
162
                                                } catch (Exception e) {
162
                                                    dateMap.put(imei, null);
163
                                                    dateMap.put(imei, null);
163
                                                }
164
                                                }
164
                                            } else {
165
                                            } else {
165
                                                System.out.println("Could not capture date");
166
                                                LOGGER.warn("Could not capture date");
166
                                                dateMap.put(imei, null);
167
                                                dateMap.put(imei, null);
167
                                            }
168
                                            }
168
                                            if (dateMap.size() == imeis.size()) {
169
                                            if (dateMap.size() == imeis.size()) {
169
                                                return dateMap;
170
                                                return dateMap;
170
                                            }
171
                                            }
Line 172... Line 173...
172
                                            captchaNotBroken = false;
173
                                            captchaNotBroken = false;
173
                                            checkAgainButton.click();
174
                                            checkAgainButton.click();
174
                                            break;
175
                                            break;
175
                                        }
176
                                        }
176
                                    } catch (Throwable e) {
177
                                    } catch (Throwable e) {
177
                                        System.out.println("Failed = " + counter + " ----------" + e.getMessage());
178
                                        LOGGER.warn("Failed = " + counter + " ----------" + e.getMessage());
178
                                    }
179
                                    }
179
                                }
180
                                }
180
                            }
181
                            }
181
                            System.out.println("After circles conditions");
182
                            LOGGER.info("After circles conditions");
182
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
183
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
183
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
184
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
184
                            slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
185
                            slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
185
                            actionProvider.moveToElement(slideButton).doubleClick().perform();
186
                            actionProvider.moveToElement(slideButton).doubleClick().perform();
186
                            System.out.println("Ending Do" + counter++);
187
                            LOGGER.info("Ending Do" + counter++);
187
 
188
 
188
                        } while (captchaNotBroken && counter <= 20);
189
                        } while (captchaNotBroken && counter <= 20);
189
                        System.out.println("Counter reached upto 20");
190
                        LOGGER.warn("Counter reached upto 20");
190
                    } catch (Exception e) {
191
                    } catch (Exception e) {
191
                        System.out.println("Caught unknown - for imei " + imei);
192
                        LOGGER.error("Oppo warranty check failed for imei " + imei, e);
192
                        e.printStackTrace();
-
 
193
                    }
193
                    }
194
                    driver.get("https://support.oppo.com/in/warranty-check/");
194
                    driver.get("https://support.oppo.com/in/warranty-check/");
195
                }
195
                }
196
                mainCount++;
196
                mainCount++;
197
                remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
197
                remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
Line 200... Line 200...
200
        } finally {
200
        } finally {
201
            if (driver != null) {
201
            if (driver != null) {
202
                try {
202
                try {
203
                    driver.quit(); //Ensures cleanup even on return or error
203
                    driver.quit(); //Ensures cleanup even on return or error
204
                } catch (Exception e) {
204
                } catch (Exception e) {
205
                    System.out.println("Error closing driver: " + e.getMessage());
205
                    LOGGER.warn("Error closing driver: " + e.getMessage());
206
                }
206
                }
207
            }
207
            }
208
        }
208
        }
209
 
209
 
210
        return dateMap;
210
        return dateMap;
Line 219... Line 219...
219
        double[] movedCircles = getMatCircles2(driver, fileName2);
219
        double[] movedCircles = getMatCircles2(driver, fileName2);
220
        if (movedCircles == null) return 0;
220
        if (movedCircles == null) return 0;
221
        double movedFirst = movedCircles[0];
221
        double movedFirst = movedCircles[0];
222
        double movedSecond = movedCircles[1];
222
        double movedSecond = movedCircles[1];
223
        //System.out.println("Test Offset Move " + testMove);
223
        //System.out.println("Test Offset Move " + testMove);
224
        System.out.println("Found Moved " + movedFirst + " ," + movedSecond);
224
        LOGGER.info("Found Moved " + movedFirst + " ," + movedSecond);
225
        double movedDistance = Math.abs(movedFirst - movedSecond);
225
        double movedDistance = Math.abs(movedFirst - movedSecond);
226
        double moved = distance - movedDistance;
226
        double moved = distance - movedDistance;
227
		/*System.out.println("Original distance " + distance);
227
		/*LOGGER.info("Original distance " + distance);
228
		System.out.println("Moved Distance " + movedDistance);
228
		LOGGER.info("Moved Distance " + movedDistance);
229
		System.out.println("Moved " + moved);*/
229
		LOGGER.info("Moved " + moved);*/
230
        if (moved == 0) return 0;
230
        if (moved == 0) return 0;
231
        int moveBy = (int) ((movedDistance) * (15 / moved));
231
        int moveBy = (int) ((movedDistance) * (15 / moved));
232
        //int moveBy = (int) distance - 21;
232
        //int moveBy = (int) distance - 21;
233
        return moveBy;
233
        return moveBy;
234
    }
234
    }