ã¯ããã«
ãããã«ã¡ã¯ãtuq376sã§ããä»åã¯æè¿è§¦ãå§ããE2Eãã¹ãã®ãã¬ã¼ã ã¯ã¼ã¯ãTestCafeã§ã®åæ©çãªç»é¢æä½ã«ã¤ãã¦ã¾ã¨ãããã¨æãã¾ãã
ãã¨ããã®ããTestCafeã¯TypeScriptãç¨ãã¦è¨è¿°ããã®ã§ããã ããããèªåãTypeScriptãåãã¦ãã¤ãJavaScriptãèªä¿¡ãæã£ã¦ããããæ¸ããï¼ãã¨ã¯è¨ããªãã¬ãã«ãªã®ã§ã ã¾ãã¯ãããæ¸ãã°ã¨ããããåä½ãããããè¦ãã¦ãããã¨ãã次第ã§ãã ã
- ã¯ããã«
- ã¢ã¯ã»ã¹å ã¨ãã¹ãã±ã¼ã¹
- è¦ç´ ãåå¾
- ã¯ãªãã¯
- ããã¹ããã£ã¼ã«ãã¸ã®å ¥å
- ãã¡ã¤ã«ã¢ãããã¼ã
- ãããã«
ã¢ã¯ã»ã¹å ã¨ãã¹ãã±ã¼ã¹
ãã¾ãã¯ã¢ã¯ã»ã¹å ã®æå®ã¨ãã¹ãã±ã¼ã¹ã®æ¸ãæ¹ããã
fixture("ãµã³ãã«").page("https://hogehoge/"); test("ãã¹ãã±ã¼ã¹1" , async (t) => { //ãã¹ãå 容 }); test("ãã¹ãã±ã¼ã¹2" , async (t) => { //ãã¹ãå 容 });
ãfixtureã¯è¤æ°ã®ãã¹ãã±ã¼ã¹ãã¾ã¨ããã«ãã´ãªã®å½¹å²ãæããã¾ãã
ããã¦ç¶ã.page
ã¯å§ãã«ã¢ã¯ã»ã¹ããURLãæå®ãã¦ãã¾ãã.beforeEachã.afterEachã§äºåã»äºå¾å¦çãè¨è¿°ãããã¨ãã§ããããã§ãã
ãå®éã®ãã¹ãã±ã¼ã¹ã¯testã§å®£è¨ãã¾ããå®è¡çµæã§ã¯ãã®ãã¹ãã±ã¼ã¹ãã¨ã«æåã¨å¤±æãè¿ãããå½¢ã«ãªãã¾ãã
è¦ç´ ãåå¾
ãããããã®å
容ã¯ãtestã®ä¸ã§æ¸ãã¦ããã¾ãã
ã¾ãã¯ç»é¢ãæä½ãã¦ããããã«ããã¼ã¸ä¸ã®è¦ç´ ãå¤æ°ã«åå¾ãã¦ããã¾ãã
const button = Selector('input').withAttribute("value","ãã¿ã³").nth(0);
ãSelectorã¯æå®ããè¦ç´ ãåå¾ãã¾ããããã«ã¯ã¿ã°åã ãã§ã¯ãªããclass ã id ãæå®ãããã¨ãã§ãã¾ãã
ãWithAttributeã¯ãå±æ§ã®ååã¨å¤ã§è¦ç´ ãçµãè¾¼ã¿ã¾ãããªã³ã¯ããã¿ã³ãªã©ã§ããã°ãã ãããããã§ä¸æã«çµããã®ã§ã¯ãªããã¨æãã¾ãã
ãããã§ãä¸æã«ãªããªãæï¼èªåã¯åãå±æ§ãæã£ãè¦ç´ ã並ã¶ä¸è¦§ç»é¢ã§ã¤ã¾ã¥ãã¾ããï¼ã便å©ãªã®ãnthã§ããããã¯æ¡ä»¶ã«ä¸è´ããè¦ç´ ã®ãã¡ãä¸ããä½çªç®ã®è¦ç´ ãåå¾ããããæå®ã§ãã¾ãããããç´ æµãªã®ã¯ãHTMLä¸ã§ä½çªç®ã«ãªãããåãã§ããã°ãããå±æ§ã®å¤ãå¤æ´ãããã¨ãã¦ããã¹ãã³ã¼ããæ¸ãç´ããã«æ¸ãã¨ããã§ãã
ã¯ãªãã¯
ããã¦ãããããç»é¢èªä½ã®æä½ã§ãã
await t.click('#nextLink');
ãã¯ãªãã¯æä½ã¯clickã§è¡ãã¾ããè¦ç´ ã®æå®ã¯ä¸è¨ã®ããã«idãç´æ¥æ¸ããããå ã»ã©ã®Selectorã§åå¾ãããã®ã渡ããããã¾ãã
ãããã§æå®ãããã®ãè¤æ°ã«è©²å½ãã¦ãã¾ã£ã¦ããã¨ãã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ãã®ã§æ³¨æã§ããï¼ä¾ãã°ä¸ã¤ãããã¿ã³ããªãã¨æã£ã¦ããããå®ã¯hiddenç¶æ ã®åããã¿ã³ãããä¸ã¤åå¨ãã¦ããã¨ãâ¦â¦ããã¾ããï¼
ããã¹ããã£ã¼ã«ãã¸ã®å ¥å
ãç¶ãã¦ãããã¹ããã£ã¼ã«ãã¸ã®å ¥åæä½ã«ã¤ãã¦ã§ãã
const textArea = Selector('input').withAttribute("name","å ¥åå ´æ"); await t.typeText(textArea, "å ¥åãããå¤");
ãtypeTextãç¨ãã¾ããSelectorã§åå¾ããããã¹ãã¨ãªã¢è¦ç´ ã¨ãå ¥åããå¤ãæå®ãã¾ãã
ãã©ãããæå®ããè¦ç´ ãã¯ãªãã¯ãã¦ãã©ã¼ã«ã¹ãã¦ããå ¥åãè¡ã£ã¦ããããã§ãã¯ãªãã¯ãã段éã§æ£ãããã©ã¼ã«ã¹ã§ããªãã£ãå ´åãæ¸ãè¾¼ã¿ã¯è¡ãããªãããã§ãã
ãã¡ã¤ã«ã¢ãããã¼ã
ãæå¾ã«ããã¡ã¤ã«ãã¢ãããã¼ãããæä½ã§ãã
await t.setFilesToUpload(linkInputFile, "ãã¡ã¤ã«ãã¹");
ãsetFilesToUploadã使ã£ã¦ããã¡ã¤ã«ãè¨å®ããè¦ç´ ã¨ãã¡ã¤ã«ãã¹ãè¨è¿°ãã¾ãããã¡ã¤ã«ãã¹ã¯[ 'ãã¡ã¤ã«1', 'ãã¡ã¤ã«2', 'ãã¡ã¤ã«3' ]ã¨ãã£ãããã«è¤æ°ãæå®ãããã¨ãå¯è½ã§ãã
ãããã«
ãã¨ããããã§ããããããããã°æä½éãã¹ãã±ã¼ã¹ãä½ã£ã¦ç»é¢æä½ãã¦ã¿ããã¨ãããã¨ã¯ã§ããã¯ãã§ãã
ããã¹ãã¨è¨ãã¤ã¤ã¢ãµã¼ã·ã§ã³ã«ã¯è§¦ãããã¦ãã¾ãããããã¡ãã¯ã¾ãããå°ãç解ã§ãããããããè¨äºã«ãã¦ã¿ãããªã¨æãã¾ãã