| Line 36... |
Line 36... |
| 36 |
public CheckOppoWarrantyTask(List<String> imeis) {
|
36 |
public CheckOppoWarrantyTask(List<String> imeis) {
|
| 37 |
this.imeis = imeis;
|
37 |
this.imeis = imeis;
|
| 38 |
}
|
38 |
}
|
| 39 |
|
39 |
|
| 40 |
@Override
|
40 |
@Override
|
| 41 |
public Map<String, LocalDate> call() throws Exception {
|
41 |
public Map<String, LocalDate> call() {
|
| 42 |
return checkWarranty(imeis);
|
42 |
return checkWarranty(imeis);
|
| 43 |
}
|
43 |
}
|
| 44 |
|
44 |
|
| 45 |
private Map<String, LocalDate> checkWarranty(List<String> imeis) throws Exception {
|
45 |
private Map<String, LocalDate> checkWarranty(List<String> imeis) {
|
| 46 |
String name = Thread.currentThread().getName();
|
46 |
String name = Thread.currentThread().getName();
|
| 47 |
Map<String, LocalDate> dateMap = new HashMap<>();
|
47 |
Map<String, LocalDate> dateMap = new HashMap<>();
|
| 48 |
OpenCV.loadShared();
|
48 |
OpenCV.loadShared();
|
| 49 |
LOGGER.info("Initiating webdriver...");
|
49 |
LOGGER.info("Initiating webdriver...");
|
| 50 |
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
|
50 |
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
|
| Line 54... |
Line 54... |
| 54 |
prefsMap.put("download.prompt", false);
|
54 |
prefsMap.put("download.prompt", false);
|
| 55 |
prefsMap.put("download.directory_upgrade", true);
|
55 |
prefsMap.put("download.directory_upgrade", true);
|
| 56 |
|
56 |
|
| 57 |
ChromeOptions options = new ChromeOptions();
|
57 |
ChromeOptions options = new ChromeOptions();
|
| 58 |
options.setExperimentalOption("prefs", prefsMap);
|
58 |
options.setExperimentalOption("prefs", prefsMap);
|
| 59 |
//options.setExperimentalOption("detach", true);
|
59 |
options.setExperimentalOption("detach", true);
|
| 60 |
options.addArguments("--headless");
|
60 |
//options.addArguments("--headless");
|
| 61 |
options.addArguments("--user-agent=\"Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 640 XL LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166\"");
|
61 |
options.addArguments("--user-agent=\"Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 640 XL LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166\"");
|
| 62 |
|
62 |
|
| 63 |
options.addArguments("--no-sandbox");
|
63 |
options.addArguments("--no-sandbox");
|
| 64 |
options.addArguments("start-maximized");
|
64 |
options.addArguments("start-maximized");
|
| 65 |
options.addArguments("disable-infobars");
|
65 |
options.addArguments("disable-infobars");
|
| Line 71... |
Line 71... |
| 71 |
driver.manage().window().setSize(new Dimension(1600, 900));
|
71 |
driver.manage().window().setSize(new Dimension(1600, 900));
|
| 72 |
driver.manage().window().maximize();
|
72 |
driver.manage().window().maximize();
|
| 73 |
// Deleting all the cookies
|
73 |
// Deleting all the cookies
|
| 74 |
driver.manage().deleteAllCookies();
|
74 |
driver.manage().deleteAllCookies();
|
| 75 |
// Specifiying pageLoadTimeout and Implicit wait
|
75 |
// Specifiying pageLoadTimeout and Implicit wait
|
| 76 |
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
|
76 |
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
|
| 77 |
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
77 |
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
|
| 78 |
|
78 |
|
| 79 |
driver.get("https://support.oppo.com/in/warranty-check/");
|
79 |
driver.get("https://support.oppo.com/in/warranty-check/");
|
| 80 |
int mainCount = 0;
|
80 |
int mainCount = 0;
|
| 81 |
List<String> remainingImeis = imeis;
|
81 |
List<String> remainingImeis = imeis;
|
| - |
|
82 |
WebDriverWait wait10Sec = new WebDriverWait(driver, 10);
|
| - |
|
83 |
WebDriverWait wait5Sec = new WebDriverWait(driver, 5);
|
| - |
|
84 |
WebElement slideButton;
|
| - |
|
85 |
Actions actionProvider = new Actions(driver);
|
| 82 |
do {
|
86 |
do {
|
| 83 |
for (int i = 0; i < remainingImeis.size(); i++) {
|
87 |
for (int i = 0; i < remainingImeis.size(); i++) {
|
| 84 |
try {
|
88 |
try {
|
| 85 |
String imei = remainingImeis.get(i);
|
89 |
String imei = remainingImeis.get(i);
|
| 86 |
System.out.println("Starting fresh with new IMEI " + imei);
|
90 |
System.out.println("Starting fresh with new IMEI " + imei);
|
| 87 |
driver.findElement(By.className("el-input__inner")).sendKeys(imei);
|
91 |
driver.findElement(By.className("el-input__inner")).sendKeys(imei);
|
| 88 |
driver.findElement(By.className("el-button--primary")).click();
|
92 |
driver.findElement(By.className("el-button--primary")).click();
|
| 89 |
|
93 |
|
| 90 |
WebDriverWait wait10Sec = new WebDriverWait(driver, 10);
|
- |
|
| 91 |
WebElement slideButton = null;
|
- |
|
| 92 |
Actions actionProvider = new Actions(driver);
|
- |
|
| 93 |
// Perform click-and-hold action on the element
|
94 |
// Perform click-and-hold action on the element
|
| 94 |
int counter = 1;
|
95 |
int counter = 1;
|
| 95 |
String fileName = "/tmp/" + name + "-simple.png";
|
96 |
String fileName = "/tmp/" + name + "-simple.png";
|
| 96 |
int moveBy = 0;
|
97 |
boolean captchaBroken = false;
|
| 97 |
do {
|
98 |
do {
|
| 98 |
System.out.println("Starting Do");
|
99 |
System.out.println("Starting Do");
|
| 99 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_wrapper_1")));
|
100 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_wrapper_1")));
|
| 100 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_slider_1")));
|
101 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_slider_1")));
|
| 101 |
slideButton = driver.findElement(By.id("dx_captcha_basic_slider_1"));
|
102 |
slideButton = driver.findElement(By.id("dx_captcha_basic_slider_1"));
|
| Line 105... |
Line 106... |
| 105 |
double firstCircleX = circles.get(0, 0)[0];
|
106 |
double firstCircleX = circles.get(0, 0)[0];
|
| 106 |
double secondCircleX = circles.get(0, 1)[0];
|
107 |
double secondCircleX = circles.get(0, 1)[0];
|
| 107 |
double distance = Math.abs(firstCircleX - secondCircleX);
|
108 |
double distance = Math.abs(firstCircleX - secondCircleX);
|
| 108 |
|
109 |
|
| 109 |
System.out.println("Starting Checkdistance method");
|
110 |
System.out.println("Starting Checkdistance method");
|
| 110 |
moveBy = checkDistance(driver, wait10Sec, actionProvider, distance);
|
111 |
int moveBy = checkDistance(driver, wait10Sec, actionProvider, distance);
|
| 111 |
if (moveBy > 0) {
|
112 |
if (moveBy > 0) {
|
| 112 |
System.out.println("Ending Checkdistance method " + moveBy);
|
113 |
System.out.println("Ending Checkdistance method " + moveBy);
|
| 113 |
actionProvider.moveByOffset(moveBy, 0).release().perform();
|
114 |
actionProvider.moveByOffset(moveBy, 0).release().perform();
|
| 114 |
System.out.println("Move click performed");
|
115 |
System.out.println("Move click performed");
|
| 115 |
try {
|
116 |
try {
|
| 116 |
try {
|
117 |
try {
|
| 117 |
Thread.sleep(2000);
|
- |
|
| 118 |
|
- |
|
| 119 |
WebElement verifyFailed = wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_bar-fail_1")));
|
118 |
wait5Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("dx_captcha_basic_bar-inform")));
|
| 120 |
System.out.println("Failed = " + counter);
|
119 |
System.out.println("Failed = " + counter);
|
| 121 |
counter++;
|
- |
|
| 122 |
moveBy = 0;
|
- |
|
| 123 |
} catch (Exception notFailedException) {
|
120 |
} catch (Exception notFailedException) {
|
| 124 |
System.out.println("Failed due to = + " + notFailedException.getMessage());
|
- |
|
| 125 |
System.out.println("Success at attempt " + counter);
|
121 |
System.out.println("Success at attempt " + counter);
|
| 126 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("warranty-service--result_info__wrapper")));
|
122 |
//wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.className("warranty-service--result_info__wrapper")));
|
| 127 |
try {
|
123 |
try {
|
| 128 |
String warrantyDate = driver.findElement(By.className("warranty-service--result_info__dateValue")).getText();
|
124 |
String warrantyDate = driver.findElement(By.className("warranty-service--result_info__dateValue")).getText();
|
| 129 |
System.out.println("Date -- " + warrantyDate);
|
125 |
System.out.println("Date -- " + warrantyDate);
|
| 130 |
dateMap.put(imei, LocalDate.parse(warrantyDate, DateTimeFormatter.ofPattern("yyyy/MM/dd")).minusYears(1));
|
126 |
dateMap.put(imei, LocalDate.parse(warrantyDate, DateTimeFormatter.ofPattern("yyyy/MM/dd")).minusYears(1));
|
| 131 |
} catch (Exception e) {
|
127 |
} catch (Exception e) {
|
| 132 |
System.out.println("Could not capture date");
|
128 |
System.out.println("Could not capture date");
|
| 133 |
dateMap.put(imei, null);
|
129 |
dateMap.put(imei, null);
|
| 134 |
}
|
130 |
}
|
| 135 |
WebElement checkAgainButton = driver.findElement(By.className("van-button--normal"));
|
131 |
WebElement checkAgainButton = driver.findElement(By.className("van-button--normal"));
|
| - |
|
132 |
captchaBroken = true;
|
| 136 |
checkAgainButton.click();
|
133 |
checkAgainButton.click();
|
| 137 |
//Thread.sleep(1000);
|
- |
|
| 138 |
break;
|
134 |
break;
|
| 139 |
}
|
135 |
}
|
| 140 |
} catch (Throwable e) {
|
136 |
} catch (Throwable e) {
|
| 141 |
System.out.println("Failed = " + counter + " ----------" + e.getMessage());
|
137 |
System.out.println("Failed = " + counter + " ----------" + e.getMessage());
|
| 142 |
counter++;
|
- |
|
| 143 |
moveBy = 0;
|
- |
|
| 144 |
}
|
138 |
}
|
| 145 |
}
|
139 |
}
|
| 146 |
}
|
140 |
}
|
| 147 |
System.out.println("After circles conditions");
|
141 |
System.out.println("After circles conditions");
|
| 148 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_wrapper_1")));
|
142 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_wrapper_1")));
|
| 149 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_slider_1")));
|
143 |
wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.id("dx_captcha_basic_slider_1")));
|
| 150 |
slideButton = driver.findElement(By.id("dx_captcha_basic_slider_1"));
|
144 |
slideButton = driver.findElement(By.id("dx_captcha_basic_slider_1"));
|
| 151 |
actionProvider.moveToElement(slideButton).doubleClick().perform();
|
145 |
actionProvider.moveToElement(slideButton).doubleClick().perform();
|
| 152 |
System.out.println("Ending Do");
|
146 |
System.out.println("Ending Do" + counter++);
|
| - |
|
147 |
|
| 153 |
} while (moveBy <= 0);
|
148 |
} while (!captchaBroken);
|
| 154 |
} catch (Exception e) {
|
149 |
} catch (Exception e) {
|
| 155 |
e.printStackTrace();
|
150 |
e.printStackTrace();
|
| 156 |
}
|
151 |
}
|
| 157 |
}
|
152 |
}
|
| 158 |
mainCount++;
|
153 |
mainCount++;
|
| 159 |
remainingImeis = imeis.stream().filter(x -> dateMap.containsKey(x)).collect(Collectors.toList());
|
154 |
remainingImeis = imeis.stream().filter(x -> dateMap.containsKey(x)).collect(Collectors.toList());
|
| 160 |
} while (mainCount != 10 && dateMap.size() != imeis.size());
|
155 |
} while (mainCount != 10 && dateMap.size() != imeis.size());
|
| 161 |
//Thread.sleep(5000);
|
- |
|
| 162 |
driver.close();
|
156 |
driver.close();
|
| 163 |
driver.quit();
|
157 |
driver.quit();
|
| 164 |
return dateMap;
|
158 |
return dateMap;
|
| 165 |
}
|
159 |
}
|
| 166 |
|
160 |
|