Subversion Repositories SmartDukaan

Rev

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

Rev 37446 Rev 37472
Line 13... Line 13...
13
import org.openqa.selenium.chrome.ChromeDriver;
13
import org.openqa.selenium.chrome.ChromeDriver;
14
import org.openqa.selenium.chrome.ChromeOptions;
14
import org.openqa.selenium.chrome.ChromeOptions;
15
import org.openqa.selenium.interactions.Actions;
15
import org.openqa.selenium.interactions.Actions;
16
import org.openqa.selenium.support.ui.ExpectedConditions;
16
import org.openqa.selenium.support.ui.ExpectedConditions;
17
import org.openqa.selenium.support.ui.WebDriverWait;
17
import org.openqa.selenium.support.ui.WebDriverWait;
-
 
18
import com.smartdukaan.cron.monitored.ImeiActivationGauges;
-
 
19
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.stereotype.Component;
20
import org.springframework.stereotype.Component;
19
 
21
 
20
import javax.imageio.ImageIO;
22
import javax.imageio.ImageIO;
21
import java.awt.image.BufferedImage;
23
import java.awt.image.BufferedImage;
22
import java.io.File;
24
import java.io.File;
Line 29... Line 31...
29
import java.util.stream.Collectors;
31
import java.util.stream.Collectors;
30
 
32
 
31
@Component
33
@Component
32
public class CheckRealmeWarrantyTask {
34
public class CheckRealmeWarrantyTask {
33
 
35
 
-
 
36
	@Autowired
-
 
37
	private ImeiActivationGauges gauges;
-
 
38
 
-
 
39
	private static final String BRAND = "Realme";
-
 
40
 
34
    private static final Logger LOGGER = LogManager.getLogger(CheckRealmeWarrantyTask.class);
41
    private static final Logger LOGGER = LogManager.getLogger(CheckRealmeWarrantyTask.class);
35
 
42
 
36
    static {
43
    static {
37
        try {
44
        try {
38
            OpenCV.loadShared();
45
            OpenCV.loadShared();
Line 150... Line 157...
150
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
157
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
151
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
158
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
152
                                slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
159
                                slideButton = driver.findElement(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]"));
153
                                //System.out.println("Slide button - " + slideButton);
160
                                //System.out.println("Slide button - " + slideButton);
154
                                LOGGER.info("Margin Left before- " + slideButton.getCssValue("margin-left"));
161
                                LOGGER.info("Margin Left before- " + slideButton.getCssValue("margin-left"));
-
 
162
                                gauges.captchaShown(BRAND);
155
                                actionProvider.moveToElement(slideButton).clickAndHold()
163
                                actionProvider.moveToElement(slideButton).clickAndHold()
156
                                        .moveByOffset(1, 0)//.pause(2000)
164
                                        .moveByOffset(1, 0)//.pause(2000)
157
                                        .perform();
165
                                        .perform();
158
                                pressed = true;
166
                                pressed = true;
159
 
167
 
Line 195... Line 203...
195
                                        if (json == null) {
203
                                        if (json == null) {
196
                                            LOGGER.warn("Failed = {} (captcha said: {}) urls={}",
204
                                            LOGGER.warn("Failed = {} (captcha said: {}) urls={}",
197
                                                    counter, captchaSignal(driver), seenUrls(driver));
205
                                                    counter, captchaSignal(driver), seenUrls(driver));
198
                                        } else {
206
                                        } else {
199
                                            LOGGER.info("Success  at attempt " + counter);
207
                                            LOGGER.info("Success  at attempt " + counter);
-
 
208
                                            gauges.captchaSolved(BRAND);
200
                                            //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
209
                                            //List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
201
                                            //WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
210
                                            //WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5')  or contains(text(), 'Non-Activate')]"));
202
                                            // Read the JSON the page already received. The old locator
211
                                            // Read the JSON the page already received. The old locator
203
                                            // keyed off a label that no longer exists, and its "| //h1" branch
212
                                            // keyed off a label that no longer exists, and its "| //h1" branch
204
                                            // would silently grab a page heading and try to parse it as a date.
213
                                            // would silently grab a page heading and try to parse it as a date.
Line 209... Line 218...
209
                                                    activationDate != null ? activationDate : "not activated");
218
                                                    activationDate != null ? activationDate : "not activated");
210
                                            // Always record, even with a null date. findElement used to THROW
219
                                            // Always record, even with a null date. findElement used to THROW
211
                                            // when the element was missing, so nothing was written and the imei
220
                                            // when the element was missing, so nothing was written and the imei
212
                                            // came back on every run indefinitely.
221
                                            // came back on every run indefinitely.
213
                                            dateMap.put(imei, activationDate);
222
                                            dateMap.put(imei, activationDate);
-
 
223
                                            gauges.answered(BRAND, activationDate != null);
214
                                            clearCapture(driver);
224
                                            clearCapture(driver);
215
 
225
 
216
                                            if (dateMap.size() == imeis.size()) {
226
                                            if (dateMap.size() == imeis.size()) {
217
                                                return dateMap;
227
                                                return dateMap;
218
                                            }
228
                                            }