Subversion Repositories SmartDukaan

Rev

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

Rev 37450 Rev 37472
Line 15... Line 15...
15
import org.openqa.selenium.chrome.ChromeDriver;
15
import org.openqa.selenium.chrome.ChromeDriver;
16
import org.openqa.selenium.chrome.ChromeOptions;
16
import org.openqa.selenium.chrome.ChromeOptions;
17
import org.openqa.selenium.interactions.Actions;
17
import org.openqa.selenium.interactions.Actions;
18
import org.openqa.selenium.support.ui.ExpectedConditions;
18
import org.openqa.selenium.support.ui.ExpectedConditions;
19
import org.openqa.selenium.support.ui.WebDriverWait;
19
import org.openqa.selenium.support.ui.WebDriverWait;
-
 
20
import com.smartdukaan.cron.monitored.ImeiActivationGauges;
-
 
21
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.stereotype.Component;
22
import org.springframework.stereotype.Component;
21
 
23
 
22
import javax.imageio.ImageIO;
24
import javax.imageio.ImageIO;
23
import java.awt.image.BufferedImage;
25
import java.awt.image.BufferedImage;
24
import java.io.File;
26
import java.io.File;
Line 33... Line 35...
33
import java.util.stream.Collectors;
35
import java.util.stream.Collectors;
34
 
36
 
35
@Component
37
@Component
36
public class CheckOppoWarrantyTask {
38
public class CheckOppoWarrantyTask {
37
 
39
 
-
 
40
	@Autowired
-
 
41
	private ImeiActivationGauges gauges;
-
 
42
 
-
 
43
	private static final String BRAND = "Oppo";
-
 
44
 
38
    private static final Logger LOGGER = LogManager.getLogger(CheckOppoWarrantyTask.class);
45
    private static final Logger LOGGER = LogManager.getLogger(CheckOppoWarrantyTask.class);
39
 
46
 
40
    static {
47
    static {
41
        try {
48
        try {
42
            OpenCV.loadShared();
49
            OpenCV.loadShared();
Line 138... Line 145...
138
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
145
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_wrapper_')]")));
139
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
146
                                wait10Sec.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]")));
140
                                By sliderBy = By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]");
147
                                By sliderBy = By.xpath("//*[starts-with(@id, 'dx_captcha_basic_slider_')]");
141
                                slideButton = driver.findElement(sliderBy);
148
                                slideButton = driver.findElement(sliderBy);
142
                                LOGGER.info("Margin Left before- " + marginLeftOf(slideButton));
149
                                LOGGER.info("Margin Left before- " + marginLeftOf(slideButton));
-
 
150
                                gauges.captchaShown(BRAND);
143
                                try {
151
                                try {
144
                                    actionProvider.moveToElement(slideButton).clickAndHold()
152
                                    actionProvider.moveToElement(slideButton).clickAndHold()
145
                                            .moveByOffset(1, 0)
153
                                            .moveByOffset(1, 0)
146
                                            .perform();
154
                                            .perform();
147
                                } catch (StaleElementReferenceException stale) {
155
                                } catch (StaleElementReferenceException stale) {
Line 195... Line 203...
195
                                            // which is why realme's failures name POSITION_MISMATCH and
203
                                            // which is why realme's failures name POSITION_MISMATCH and
196
                                            // oppo's 85% say nothing at all. Same line, oppo's variables.
204
                                            // oppo's 85% say nothing at all. Same line, oppo's variables.
197
                                            LOGGER.warn("Failed = {} (captcha said: {})", counter, captchaSignal(driver));
205
                                            LOGGER.warn("Failed = {} (captcha said: {})", counter, captchaSignal(driver));
198
                                        } catch (Exception notFailedException) {
206
                                        } catch (Exception notFailedException) {
199
                                            LOGGER.info("Success  at attempt " + counter);
207
                                            LOGGER.info("Success  at attempt " + counter);
-
 
208
                                            gauges.captchaSolved(BRAND);
200
 
209
 
201
                                            // Read the JSON the page itself received rather than the
210
                                            // Read the JSON the page itself received rather than the
202
                                            // rendered text. The DOM value is built from two text nodes -- the
211
                                            // rendered text. The DOM value is built from two text nodes -- the
203
                                            // date plus a "(UTC+x)" suffix derived from the browser timezone --
212
                                            // date plus a "(UTC+x)" suffix derived from the browser timezone --
204
                                            // and the old locator tested only the first, so it matched nothing.
213
                                            // and the old locator tested only the first, so it matched nothing.
Line 215... Line 224...
215
                                                        activationDate != null ? activationDate : "no activation date");
224
                                                        activationDate != null ? activationDate : "no activation date");
216
                                            }
225
                                            }
217
                                            // Always record the imei, even with a null date: findElement used to
226
                                            // Always record the imei, even with a null date: findElement used to
218
                                            // throw here, so the row was never written and came back every run.
227
                                            // throw here, so the row was never written and came back every run.
219
                                            dateMap.put(imei, activationDate);
228
                                            dateMap.put(imei, activationDate);
-
 
229
                                            gauges.answered(BRAND, activationDate != null);
220
                                            clearCapture(driver);
230
                                            clearCapture(driver);
221
 
231
 
222
                                            if (dateMap.size() == imeis.size()) {
232
                                            if (dateMap.size() == imeis.size()) {
223
                                                return dateMap;
233
                                                return dateMap;
224
                                            }
234
                                            }