Subversion Repositories SmartDukaan

Rev

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

Rev 34415 Rev 34416
Line 26... Line 26...
26
import java.util.Map;
26
import java.util.Map;
27
import java.util.concurrent.TimeUnit;
27
import java.util.concurrent.TimeUnit;
28
import java.util.stream.Collectors;
28
import java.util.stream.Collectors;
29
 
29
 
30
@Component
30
@Component
31
public class CheckOppoWarrantyTask {
31
public class CheckRealmeWarrantyTask {
32
 
32
 
33
 
33
 
34
    private static final Logger LOGGER = LogManager.getLogger(CheckOppoWarrantyTask.class);
34
    private static final Logger LOGGER = LogManager.getLogger(CheckRealmeWarrantyTask.class);
35
 
35
 
36
    public Map<String, LocalDate> checkWarranty(List<String> imeis) {
36
    public Map<String, LocalDate> checkWarranty(List<String> imeis) {
37
        Map<String, LocalDate> dateMap = new HashMap<>();
37
        Map<String, LocalDate> dateMap = new HashMap<>();
38
        //System.out.println(System.getProperty("os.name"));
38
        //System.out.println(System.getProperty("os.name"));
39
        //System.out.println(System.getProperty("os.arch"));
39
        //System.out.println(System.getProperty("os.arch"));
Line 71... Line 71...
71
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
71
        driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
72
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
72
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
73
 
73
 
74
        int mainCount = 0;
74
        int mainCount = 0;
75
        List<String> remainingImeis = imeis;
75
        List<String> remainingImeis = imeis;
76
        WebDriverWait wait10Sec = new WebDriverWait(driver, 8);
76
        WebDriverWait wait10Sec = new WebDriverWait(driver, 15);
77
        WebDriverWait wait5Sec = new WebDriverWait(driver, 4);
77
        WebDriverWait wait5Sec = new WebDriverWait(driver, 4);
78
        WebElement slideButton;
78
        WebElement slideButton;
79
        Actions actionProvider = new Actions(driver);
79
        Actions actionProvider = new Actions(driver);
80
        do {
80
        do {
81
            driver.get("https://support.oppo.com/in/warranty-check/");
81
            driver.get("https://www.realme.com/in/support/phonecheck");
82
            try {
82
            try {
83
                driver.findElement(By.cssSelector(".cp-cookie-tip a.close")).click();
83
                driver.findElement(By.cssSelector(".cp-cookie-tip a.close")).click();
84
            } catch (Exception e) {
84
            } catch (Exception e) {
85
                try {
85
                try {
86
                    System.out.println("Cookie not found");
86
                    System.out.println("Cookie not found");
Line 90... Line 90...
90
 
90
 
91
            for (int i = 0; i < remainingImeis.size(); i++) {
91
            for (int i = 0; i < remainingImeis.size(); i++) {
92
                String imei = remainingImeis.get(i);
92
                String imei = remainingImeis.get(i);
93
                try {
93
                try {
94
                    System.out.println("Starting fresh with new IMEI " + imei);
94
                    System.out.println("Starting fresh with new IMEI " + imei);
95
                    if (driver.findElement(By.className("el-input__inner")).getAttribute("value").length() > 0) {
95
                    if (driver.findElement(By.className("sn-input")).getAttribute("value").length() > 0) {
96
                        System.out.println("Darn.. leaving" + driver.findElement(By.className("el-input__inner")).getAttribute("value"));
96
                        System.out.println("Darn.. leaving" + driver.findElement(By.className("el-input__inner")).getAttribute("value"));
97
                        driver.get("https://support.oppo.com/in/warranty-check/");
97
                        driver.get("https://www.realme.com/in/support/phonecheck");
98
                        break;
98
                        break;
99
                    }
99
                    }
100
                    driver.findElement(By.className("el-input__inner")).sendKeys(imei);
100
                    driver.findElement(By.className("sn-input")).sendKeys(imei);
101
 
101
 
102
                    //driver.findElement(By.className("el-button--primary")).click();
102
                    //driver.findElement(By.className("el-button--primary")).click();
103
                    driver.findElement(By.cssSelector("div.searchBtn")).click();
103
                    driver.findElement(By.cssSelector("div.check-btn")).click();
104
 
104
 
105
                    // Perform click-and-hold action on the element
105
                    // Perform click-and-hold action on the element
106
                    int counter = 1;
106
                    int counter = 1;
107
                    boolean captchaNotBroken = true;
107
                    boolean captchaNotBroken = true;
108
                    do {
108
                    do {
109
                        String fileName = "/tmp/oppo-simple-i-" + counter + " " + System.currentTimeMillis() + ".png";
109
                        String fileName = "/tmp/oppo-simple-i-" + counter + " " + System.currentTimeMillis() + ".png";
110
                        try {
110
                        try {
111
                            System.out.println("Starting Do");
111
                            System.out.println("Starting Do");
-
 
112
                            //Thread.sleep(5000);
112
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_wrapper_1")));
113
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("canvas")));
113
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_slider_1")));
114
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='dx_captcha_basic_bg_1' or @id='dx_captcha_basic_bg_2']")));
-
 
115
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='dx_captcha_basic_wrapper_1' or @id='dx_captcha_basic_wrapper_2']")));
-
 
116
                            wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='dx_captcha_basic_slider_1' or @id='dx_captcha_basic_slider_2']")));
114
                            slideButton = driver.findElement(By.id("dx_captcha_basic_slider_1"));
117
                            slideButton = driver.findElement(By.xpath("//*[@id='dx_captcha_basic_slider_1' or @id='dx_captcha_basic_slider_2']"));
115
                            //System.out.println("Slide button - " + slideButton);
118
                            //System.out.println("Slide button - " + slideButton);
116
                            System.out.println("Margin Left before- " + slideButton.getCssValue("margin-left"));
119
                            System.out.println("Margin Left before- " + slideButton.getCssValue("margin-left"));
117
                            actionProvider.moveToElement(slideButton).clickAndHold()
120
                            actionProvider.moveToElement(slideButton).clickAndHold()
118
                                    .moveByOffset(1, 0)//.pause(2000)
121
                                    .moveByOffset(1, 0)//.pause(2000)
119
                                    .perform();
122
                                    .perform();
Line 121... Line 124...
121
                            //actionProvider.moveByOffset(-1,0).pause(2000).perform();
124
                            //actionProvider.moveByOffset(-1,0).pause(2000).perform();
122
                            System.out.println("Margin Left after - " + slideButton.getCssValue("margin-left"));
125
                            System.out.println("Margin Left after - " + slideButton.getCssValue("margin-left"));
123
                            //Thread.sleep(5000);
126
                            //Thread.sleep(5000);
124
                        } catch (Exception e) {
127
                        } catch (Exception e) {
125
                            System.out.println(e.getMessage());
128
                            System.out.println(e.getMessage());
126
                            driver.get("https://support.oppo.com/in/warranty-check/");
129
                            driver.get("https://www.realme.com/in/support/phonecheck");
127
                            break;
130
                            break;
128
                        }
131
                        }
129
                        double[] circles = getMatCircles2(driver, fileName);
132
                        double[] circles = getMatCircles2(driver, fileName);
130
                        if (circles != null) {
133
                        if (circles != null) {
131
                            double firstCircleX = circles[0];
134
                            double firstCircleX = circles[0];
Line 145... Line 148...
145
                                        wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
148
                                        wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
146
                                        System.out.println("Failed = " + counter);
149
                                        System.out.println("Failed = " + counter);
147
                                    } catch (Exception notFailedException) {
150
                                    } catch (Exception notFailedException) {
148
                                        System.out.println("Success  at attempt " + counter);
151
                                        System.out.println("Success  at attempt " + counter);
149
                                        //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
152
                                        //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
150
                                        WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
153
                                        //WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
-
 
154
                                        WebElement activationTimeElement = driver.findElement(By.xpath("//*[matches(text(), '\\d{4}\\.\\d{2}\\.\\d{2}') or contains(text(), 'not activate')]"));
-
 
155
 
151
//TODO: IF not found activationElement
156
//TODO: IF not found activationElement
152
                                        if (activationTimeElement != null) {
157
                                        if (activationTimeElement != null) {
153
                                            String activationDateString = activationTimeElement.getText().trim();
158
                                            String activationDateString = activationTimeElement.getText().trim();
154
                                            System.out.println("Date --  " + activationDateString);
159
                                            System.out.println("Date --  " + activationDateString);
155
                                            try {
160
                                            try {
156
                                                dateMap.put(imei, LocalDate.parse(activationDateString.split(" ")[0], DateTimeFormatter.ofPattern("dd/MM/yyyy")));
161
                                                dateMap.put(imei, LocalDate.parse(activationDateString.split(" ")[0], DateTimeFormatter.ofPattern("yyyy/MM/dd")).minusYears(1));
157
                                                System.out.println("Date --  " + activationDateString);
162
                                                System.out.println("Date --  " + activationDateString);
158
                                            } catch (Exception e) {
163
                                            } catch (Exception e) {
159
                                                dateMap.put(imei, null);
164
                                                dateMap.put(imei, null);
160
                                            }
165
                                            }
161
                                        } else {
166
                                        } else {
Line 165... Line 170...
165
                                        if(dateMap.size()==imeis.size()) {
170
                                        if(dateMap.size()==imeis.size()) {
166
                                            driver.close();
171
                                            driver.close();
167
                                            driver.quit();
172
                                            driver.quit();
168
                                            return dateMap;
173
                                            return dateMap;
169
                                        }
174
                                        }
170
                                        WebElement checkAgainButton = driver.findElement(By.className("c-btn"));
175
                                        WebElement checkAgainButton = driver.findElement(By.className("recheck-btn"));
171
                                        captchaNotBroken = false;
176
                                        captchaNotBroken = false;
172
                                        checkAgainButton.click();
177
                                        checkAgainButton.click();
173
                                        break;
178
                                        break;
174
                                    }
179
                                    }
175
                                } catch (Throwable e) {
180
                                } catch (Throwable e) {
Line 188... Line 193...
188
                    System.out.println("Counter reached upto 20");
193
                    System.out.println("Counter reached upto 20");
189
                } catch (Exception e) {
194
                } catch (Exception e) {
190
                    System.out.println("Caught unknown - for imei " + imei);
195
                    System.out.println("Caught unknown - for imei " + imei);
191
                    e.printStackTrace();
196
                    e.printStackTrace();
192
                }
197
                }
193
                driver.get("https://support.oppo.com/in/warranty-check/");
198
                driver.get("https://www.realme.com/in/support/phonecheck");
194
            }
199
            }
195
            mainCount++;
200
            mainCount++;
196
            remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
201
            remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
197
        } while (mainCount < 5);
202
        } while (mainCount < 5);
198
        driver.close();
203
        driver.close();