ãã®èŠçŽ ã䜿çšããããã®ãã¬ãŒã ã¯ãŒã¯ã¯ãéšã®åŸã®ããã³ã®ããã«æé·ããŸãã Canvasã䜿çšããŠããã°ã©ãã³ã°ãéå§ããæ¹æ³ã«ã€ããŠå€ãã®èšäºãæžãããŠããŸãã ãããã1ã€ã®ç¹ããããŸããæããã«ãç¹ç°æ§ãçãããã«ããã£ãã«èªãããããšã¯ã»ãšãã©ãããŸããã Canvasã§ã¢ããªã±ãŒã·ã§ã³ããã¹ãããããšã§ãã ããæå³ã§ã¯ãCSSãŸãã¯XPathã»ã¬ã¯ã¿ãŒã«ãã£ãŠããŒãžäžã®èŠçŽ ã«ã¢ã¯ã»ã¹ãããªããžã§ã¯ãã«å¯ŸããŠããã€ãã®ã¢ã¯ã·ã§ã³ãå®è¡ããããšã«æ £ããŠãããã¹ããšã³ãžãã¢ã«ãšã£ãŠã¯åé¡ã«ãªããŸãã Canvasã§ã¯ãDOMèŠçŽ ã1ã€ã§ããããã®äžã«å€ãã®ãªããžã§ã¯ããããããããã®ã¢ãããŒãã¯æ©èœããŸããã
ç«ã®äžã§ãYandex.Maps APIãã¹ãèªååã®äŸã䜿çšããŠãYandexã§ãã®åé¡ãã©ã®ããã«è§£æ±ºãããã«ã€ããŠèª¬æããŸãã
Webã€ã³ã¿ãŒãã§ãŒã¹ã®ãã¹ãæ¹æ³
ãšã³ãžãã¢ã¯ããã¹ã察象ã®ãµãŒãã¹ãåæãã ããŒãžã®Page Objectãã³ã³ãã€ã«ããŸãïŒãã¹ã¿ãŒã®èŠæ±ã«ãããããã¯HtmlElementsã©ã€ãã©ãªã䜿çšããŠå®è¡ã§ããŸãïŒã çŸããã¬ããŒããå¿ èŠãªå Žåã¯ã Thucydidesãã¬ãŒã ã¯ãŒã¯ã䜿çšã§ããŸãã 次ã«ã䜿çšå¯èœãªãã¹ãã¹ã¯ãªããã«åŸã£ãŠã WebDriver APIã䜿çšããŠèªåãã¹ããèšè¿°ããŸã ã äœãèµ·ãã£ãã®ãããã¹ã¿ãŒã¯Selenium Gridãä»ããŠãã©ãŠã¶ãŒãã¡ãŒã ã§èµ·åããé»åã¡ãŒã«ã§åä¿¡ããã¬ããŒããèŠãŠãšã©ãŒãæ¢ããŸãã
ãã¹ããã€ã³ã¿ã©ã¯ãã£ããªã°ã©ãã£ãã¯ã¹ãšå¯Ÿè©±ããŠãã§ãã¯ããå¿ èŠããªãå Žåããã¹ãŠãã·ã³ãã«ã§çŸããã§ãã ãããããããäžã®åãã¯ãªãã¯ããå¿ èŠãããå ŽåããŸãã¯ããå Žæããå¥ã®å Žæã«åè§åœ¢ããã©ãã°ããå¿ èŠãããå Žåã¯ã©ãããã°ããã§ããããïŒ CanvasãèŠã€ãããšããŠããç¹å®ã®åãå¿ èŠã ãšããŸãã ã¯ãªãã¯ããæ¹æ³ã¯ïŒ
ã°ã©ãã£ãã¯ã«çŽé¢ããŠãããŒãžãªããžã§ã¯ããä»ããåŸæ¥ã®ã¢ãããŒããããã§ã¯æ©èœããªãããšãããããŸããã ãŸããWebDriverãæåŠããããªããããéèŠãªããŒãã¹ãåŸãããŸãã人æ°ã®ãããã¹ãŠã®ãã©ãŠã¶ãŒã§ãã¹ããå®è¡ããããããŒãžã§ä»»æã®JavaScriptã³ãŒããå®è¡ãããã§ããŸãïŒJavaScript APIã®ãã¹ãã«éåžžã«äŸ¿å©ã§ãïŒã ããã«ããã®ããŒã«ã¯å€§èŠæš¡ãªéçºè ã³ãã¥ããã£ã«ãã£ãŠãµããŒããããŠããŸãã
ã€ãŸããã¢ãããŒãã¯WebDriverã«åºã¥ããŠããå¿ èŠããããŸãããåæã«ãããã¥ã¡ã³ãã®DOMããªãŒã«è¡šç€ºãããŠãããã©ããã«é¢ä¿ãªããããŒãžäžã®ãã¹ãŠã®èŠçŽ ãšããåãã§ããå¿ èŠããããŸãã ããã«ãçžäºäœçšã®çµæã確èªããJavaScriptãšã©ãŒã®å¯èœæ§ããã£ããã§ããå¿ èŠããããŸãã
ããŒãžäžã®èŠçŽ ãšã®çžäºäœçš
äžèšã§è¿°ã¹ãããã«ãYandex.Maps APIã®ã³ã³ããã¹ãã§ã€ã³ã¿ãŒãã§ã€ã¹ããã¹ãããããšãæ€èšããŸãã ãããã£ãŠãå®éã«ãã¹ãã§çžäºäœçšããå¿ èŠããããã®ãèŠãŠã¿ãŸãããã
APIã®çµæã¯ãã¬ã€ã€ãŒã±ãŒãã®ããã«èŠãããããã§ãã äžçªäžã®ã¬ã€ã€ãŒã¯å°åœ¢å³ã§ãã ãã®äžã«ã°ã©ãã£ãã¯ã¬ã€ã€ãŒããããŸãã ãããã¯ãCanvas DOM以å€ã®èŠçŽ ã䜿çšããŠè¡šç€ºã§ããããŸããŸãªã«ãŒããã«ãŒã©ãŒã©ã€ã³ãããã«ã¯ã©ãã«ã§ãã 3çªç®ã¯ã€ãã³ãã¬ã€ã€ãŒã§ããã®äžã«ã¯ãã¹ãŠã®çš®é¡ã®ãããã³ã³ãããŒã«ïŒãã¿ã³ãããããããŠã³ã¡ãã¥ãŒãå ¥åãã£ãŒã«ããã¹ã©ã€ããŒãªã©ïŒãæ¢ã«é 眮ãããŠããŸãã
ãã®ããã€ãã§ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ã®æ®ãã®éšåãåå¥ã®DOMèŠçŽ ãšããŠè¡šç€ºãããWebDriverã䜿çšããŠç°¡åã«ã¯ãªãã¯ã§ãããããã°ã©ãã£ãã¯ã¬ã€ã€ãŒãšã®å¯Ÿè©±ã«é¢å¿ããããŸãã Yandex.Maps APIã®ãŠãŒã¶ãŒã¯ãããã¹ãŠã®ã°ã©ãã£ãã¯ãªããžã§ã¯ãçšã®APIãããããããä»ããŠCanvasäžã®èŠçŽ ãšããåãããŸããããšèšãããšãã§ããŸãã
ãããŠãããã¯ãŸãã«å€ãã®ãšã³ãžãã¢ãCanvasäžã®ãªããžã§ã¯ããæäœããããã«äœ¿çšããã¢ãããŒãã§ãã ãããã圌ã«ã¯1ã€ã®åé¡ããããŸã-圌ã¯ãŠãŒã¶ãŒã®å®éã®è¡åããã¯ã»ã©é ãã§ãã å¹³åçãªäººã¯ãã«ãŒããå°å³ã«è¡šç€ºããJavaScriptãªããžã§ã¯ãã®ã³ã³ãœãŒã«
click()
ãåŒã³åºããŸããã 圌ã¯ç»åã®äžã®ããŠã¹ãåããã¯ãªãã¯ããã ãã§ãã
click()
ã¡ãœããã®å¹çã¯ãå®éã®ã¯ãªãã¯ã®æ£ããåŠçãä¿èšŒãããã®ã§ã¯ãããŸããã ãããã£ãŠãç§ãã¡ã¯ç¬èªã®å¥ã®æ¹æ³ãæ¡çšããŸããã
Canvasãšã®ããè¯ã察話æ¹æ³ãç解ããã«ã¯ããŠãŒã¶ãŒãã¯ãªãã¯ãããªããžã§ã¯ããããã°ã©ã èªäœãã©ã®ããã«ç解ããããç¥ãå¿ èŠããããŸãã Yandex.Maps APIã®å Žåã ã¢ã¯ãã£ããšãªã¢ã®ãã¯ãããžãŒã䜿çšãããŸãã Canvasã«ã€ã³ã¿ã©ã¯ãã£ããªèŠçŽ ãããå Žåã¯ãã€ã§ãã䌌ããããªãã®ã䜿çšãããŸãã
ã¢ã¯ãã£ããšãªã¢ã®æè¡ã®äžè¬çãªã¢ã«ãŽãªãºã ïŒ
- ãã®ããã°ã©ã ã¯ãCanvasã«æç»ããããã¹ãŠã®èŠçŽ ããã¯ã»ã«åº§æšã«é¢ããæ å ±ãä¿åããŸãã
- ã°ã©ãã£ãã¯ãªããžã§ã¯ãã§çºçããããŠã¹ã€ãã³ãããã£ããããŸãã ããã¯Canvasã§çŽæ¥è¡ãããšãã§ããŸãã ãã®äŸã§ã¯ãã°ã©ãã£ãã¯ã¹ã¬ã€ã€ãŒã®äžã«ããã¹ãŠãã«ããŒããã€ãã³ãã®ç¹å¥ãªéæã¬ã€ã€ãŒããããŸãã
- ããŠã¹ã€ãã³ãã®åº§æšã¯ãªããžã§ã¯ãã®åº§æšãšçžé¢ããŠãããã€ãã³ããäœããã®ãªããžã§ã¯ãã§çºçããå Žåã察å¿ãããã³ãã©ãŒãåŒã³åºãããŸãã
ç¹å®ã®ã°ã©ãã£ãã¯ãªããžã§ã¯ãã¯å¿ èŠãããŸãããã€ãã³ãã®åº§æšãéžæããCanvasãŸãã¯ã€ãã³ãã®ããã€ãã®ã¬ã€ã€ãŒã«ã¹ããŒããã ãã§ãã ããããããã¯ããã»ã©åçŽã§ã¯ãããŸããã ã©ãã«ãã¯ãªãã¯ããå¿ èŠããããšããŸãããã ç®ã§åº§æšã決å®ããã®ã¯ç°¡åãªããšã§ã¯ãããŸããã
ãã¯ã»ã«ã«äŸåããå Žåããµã€ãºã512 x 512ã®Canvasãªããžã§ã¯ãã®å Žåã512x512ã®çžäºäœçšç¹ãåŸãããŸãã å€ãããã ç掻ã楜ã«ããããã«ããã£ã³ãã¹ãæ¡ä»¶ä»ãã®åè§ã«åå²ããããã«äŸ¿å©ãªããã«ããã£ã³ãã¹ã®äžã«åéæã®èæ¯ã衚瀺ããŠããã¹ããšã³ãžãã¢ãç®ã§èŠãããããã«ããŸãã 32ãã¯ã»ã«ã«çããæ£æ¹åœ¢ã®èŸºã®ãµã€ãºãéžæããŸããã
ããŒã¯ãã¯ã£ãããšèŠããããã«ãªããŸãããããŒã¯ãã¯ãªãã¯ããã«ã¯ã座æš[11ã11]ã®æ£æ¹åœ¢ã®äžå¿ãã¯ãªãã¯ããå¿ èŠããããŸãã æ£æ¹åœ¢ã®èŸºã®ãµã€ãºãããããšããããã®åº§æšã¯éåžžã®ãã¯ã»ã«åº§æšã«ç°¡åã«å€æããããã£ã³ãã¹äžã®ã¯ãªãã¯ãåŒã³åºãããŸãã
x = 11 * 32 + 32 / 2; y = 11 * 32 + 32 / 2; click(x, y); // click(368, 368);
DOMããªãŒããã¢ã¯ã»ã¹ããããšãã§ããŸããããã®ã¢ãããŒãã䜿çšããŠãããã³ã³ãããŒã«ãšããåãããããšã泚ç®ã«å€ããŸãã ããã¯ããããäžã®ãã¹ãŠã®èŠçŽ ãžã®ã¢ããŒã«ãåãã¹ã¿ã€ã«ã«ãªãããã«è¡ãããŸãã æ®å¿µãªãããWebDriverã¯ãŠã£ã³ããŠã®ä»»æã®ãã€ã³ãã§ã€ãã³ããã¹ããŒããããšã¯ã§ããŸããããDOMããªãŒã®ç¹å®ã®èŠçŽ ã§ã®ã¿ã¹ããŒããŸãã ãããã£ãŠãã€ãã³ããçºçãããåã«ãçžäºäœçšã®èŠçŽ ãå®çŸ©ããŸãã ããã¯ã
document
ãªããžã§ã¯ãã®
elementFromPoint(x, y)
ã¡ãœãããä»ããŠè¡ãããŸãã ãã®æç¹ã§ãã¿ã³ãããå Žåãã°ã©ãã£ãã¯ãCanvasäžã«ããå Žåãã€ãã³ãããã®ãã¿ã³ã«ã¹ããŒãããŸãã
çžäºäœçšãæ€èšŒãã
ãã¿ã³ãæŒããšããã®å€èŠ³ãå€ãããŸã-æŒãã¢ãã¡ãŒã·ã§ã³ãçºçããŸãã ãã¹ãã§ã¯ãèŠçŽ ã®DOMå±æ§ã®å€ãèŠæ±ããããšã«ããããã®ã¢ãã¡ãŒã·ã§ã³ã確èªã§ããŸããããã¯ããã¿ã³ã®å€èŠ³ãæ åœããŸãã å¿ èŠãªã¯ã©ã¹ã衚瀺ãããŸãã-ããã¯ãã¢ãã¡ãŒã·ã§ã³ãçºçããããšãæå³ããŸãã Canvasã«æç»ããããªããžã§ã¯ãã®å Žåãç¶æ³ã¯å€å°ç°ãªããŸãã ããã§ã¯ãã¯ã©ã¹ãŸãã¯ããŒãžäžã®äœçœ®ããªã¯ãšã¹ãã§ããªããªããŸããã Canvasã®ã¿ããããã®å±æ§ãæã¡ãŸãããDOMããªãŒã«ã¯ãªããããããã«æç»ããããªããžã§ã¯ãã¯æã¡ãŸããã ã§ã¯ãã©ã€ã³ãæ£ããè²ã«ããããŠã¹ã§ãã©ãã°ããåŸã«ããªãŽã³ã®äœçœ®ãå€æŽããããã©ãããã©ã®ããã«ç¢ºèªããŸããïŒ
äžæ¹ã§ã¯ãCanvasã«è¡šç€ºãããJavaScriptãªããžã§ã¯ããåç §ããŠãè²ãšäœçœ®ããªã¯ãšã¹ãã§ããŸãã ããããããªããèŠããŠããããã«ãAPIãç§ãã¡ã«åãã€ããªãããšã誰ãä¿èšŒããŸããã ã³ãŒãã«èª€ããããå¯èœæ§ããããŸããJavaScriptã«ãããè¡ãèµ€ã§ããããšãããããç®ã§èŠããšéã§ããããšãããããŸãã
ãããã解決çã¯ãããŸãã ã€ã³ã¿ãŒãã§ã€ã¹ã®å®å®ããããŒãžã§ã³ã®å€èŠ³ãšãã¹ãæžã¿ã®ã€ã³ã¿ãŒãã§ã€ã¹ã®å€èŠ³ãæ¯èŒããã ãã§ååã§ãã ã€ãŸãã2ã€ã®ãã©ãŠã¶ãŒãŠã£ã³ããŠã®ã¹ãããã·ã§ãããæ¯èŒããŸãã ããã次ã®ããã«è¡ããŸãã
- ããæç¹ã§ãã€ã³ã¿ãŒãã§ãŒã¹ã®äž¡æ¹ã®ããŒãžã§ã³ãéããŸãã
- äž¡æ¹ã®ããŒãžã§ã³ã¯ãç°ãªããã©ãŠã¶ãŒãŠã£ã³ããŠã§åããã©ãŠã¶ãŒããŒãžã§ã³ã§éããŸãã
- äž¡æ¹ã®ãŠã£ã³ããŠã®ã€ã³ã¿ãŒãã§ã€ã¹ã§åãã¢ã¯ã·ã§ã³ãå®è¡ããŸãã
- é©åãªã¿ã€ãã³ã°ã§ããŠã£ã³ããŠã®åçãæ®ãããã¯ã»ã«ããšã«æ¯èŒããŸãã
ãã®äžé£ã®ã¢ã¯ã·ã§ã³ã«ãããã€ã³ã¿ãŒãã§ã€ã¹ã®å€èŠ³ã®æ¯èŒã«é¢é£ããå€ãã®åé¡ãåãé€ãããšãã§ããŸãã ãŸãããã¹ãã¯æéãšãšãã«å€åããæ å ±ãšã¯ç¡é¢ä¿ã§ãã 第äºã«ããã©ãŠã¶äŸåã®ã¬ã€ã¢ãŠãã«å¯ŸããæµæããããŸãã ãããŠç¬¬äžã«ãåç §ç»åãä¿åããªãã§ãã ããã
JavaScriptãšã©ãŒè¿œè·¡
ãã¹ãã¢ãããŒãã®æåŸã®ãã€ã³ãã¯ãJavaScriptãšã©ãŒããã£ããããããšã§ãã ããã§ã¯ãäžèŠããã¹ãŠãç°¡åã§ããwindowãªããžã§ã¯ãã®onerrorã¡ãœããã䜿çšããŸãã çè«çã«ã¯ãã¹ãŠåé¡ãããŸããããå®éã«ã¯ãã®ã¢ãããŒãã«ã¯1ã€ã®å€§ããªåé¡ããããŸãã ãã©ãŠã¶ã§éããŠãããã¹ã以å€ã®ãã¹ãã§ãšã©ãŒãçºçããå Žåããã®ããã¹ããèªã¿åãããšã¯ã§ããŸããã ã©ããã
次ã®2ã€ã®ãªãã·ã§ã³ããããŸãã
- ãµãŒããŒã®å¿çã«ç¹å®ã®ããããŒãè¿œå ããŸãïŒ ãã¹ãŠã®ãã©ãŠã¶ãŒã§æ©èœããããã§ã¯ãããŸãã ïŒã
- ãã©ãŠã¶ã³ã³ãœãŒã«ã¬ãã«ã§ãšã©ãŒãåéããFirefoxçšã®ãã©ã°ã€ã³ã䜿çšããŸã ã
ã©ã¡ããéžã¶ãã¯ããªã次第ã§ãã ã©ã¡ãã®ãªãã·ã§ã³ã«ãçåœæš©ããããŸãã
çµæã¯äœã§ããïŒ
å€æããããã«ãCanvasã䜿çšããŠåäœããWebã€ã³ã¿ãŒãã§ã€ã¹ããã¹ãããã¿ã¹ã¯ã¯ãéåžžã®WebDriverã䜿çšããŠéåžžã«ããŸã解決ãããŸãã ããããçŸæç¹ã§ã¯ãããã«çãŸããããã¹ããšã€ã³ã¿ãŒãã§ãŒã¹ã®çžäºäœçšã®æ¹åã«ç®ãåããããšã«ããŸããã ããã§DOMèŠçŽ ã§JavaScriptã€ãã³ããã¹ããŒããå Žåãå°æ¥çã«ã¯ãŠãŒã¶ãŒãšåãæ¹æ³ã§ãããå®è¡ããããšèããŠããŸãã ããŠã¹ãšããŒããŒãã®å®éã®å¶åŸ¡ãèšç»ããŠããŸãã ããã«ã¯Awt.Robotã䜿çšãããŸãã ãã¥ãŒã¹ããã©ããŒããŠãã ããïŒ