|
| 1 | +// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package software.aws.toolkits.jetbrains.uitests.docTests.scripts |
| 5 | + |
| 6 | +// language=TS |
| 7 | +val updateReadmeLatestChangesConfirmOptionsScript = """ |
| 8 | + const puppeteer = require('puppeteer'); |
| 9 | + |
| 10 | + async function testNavigation() { |
| 11 | + const browser = await puppeteer.connect({ |
| 12 | + browserURL: 'http://localhost:9222' |
| 13 | + }) |
| 14 | +
|
| 15 | + try { |
| 16 | +
|
| 17 | + const pages = await browser.pages() |
| 18 | + |
| 19 | + for(const page of pages) { |
| 20 | + const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root')); |
| 21 | + |
| 22 | + const element = await page.${'$'}('.mynah-chat-prompt-input') |
| 23 | + if(element) { |
| 24 | + |
| 25 | + console.log('Typing /doc in the chat window') |
| 26 | +
|
| 27 | + await page.type('.mynah-chat-prompt-input', '/doc') |
| 28 | + await page.keyboard.press('Enter') |
| 29 | +
|
| 30 | + console.log('Attempting to find and click Update an existing README button') |
| 31 | + await findAndClickButton(page, 'Update an existing README', true, 10000) |
| 32 | + console.log('Attempting to find and click Update README to reflect code button') |
| 33 | + await findAndClickButton(page, 'Update README to reflect code', true, 10000) |
| 34 | + console.log('Attempting to find all available buttons') |
| 35 | + const yesButton = await findAndClickButton(page, 'Yes', false, 10000) |
| 36 | + const changeFolderButton = await findAndClickButton(page, 'Change folder', false, 10000) |
| 37 | + const cancelButton = await findAndClickButton(page, 'Cancel', false, 10000) |
| 38 | +
|
| 39 | + if (!yesButton || !changeFolderButton || !cancelButton) { |
| 40 | + console.log('Error: Test Failed') |
| 41 | + console.log('Unable to find buttons for Yes/ChangeFolder/Cancel') |
| 42 | + } else { |
| 43 | + console.log('Found all expected buttons') |
| 44 | + console.log('Test Successful') |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | +
|
| 49 | + } finally { |
| 50 | + await browser.close(); |
| 51 | + } |
| 52 | + } |
| 53 | +
|
| 54 | + testNavigation().catch((error) => { |
| 55 | + console.log('Error: Test Failed'); |
| 56 | + console.error(error); |
| 57 | + }); |
| 58 | +""".trimIndent() |
| 59 | + |
| 60 | +// language=TS |
| 61 | +val updateReadmeLatestChangesScript = """ |
| 62 | +
|
| 63 | + const puppeteer = require('puppeteer'); |
| 64 | +
|
| 65 | + async function testNavigation() { |
| 66 | + const browser = await puppeteer.connect({ |
| 67 | + browserURL: 'http://localhost:9222' |
| 68 | + }) |
| 69 | + |
| 70 | + try { |
| 71 | + |
| 72 | + const pages = await browser.pages() |
| 73 | + |
| 74 | + for(const page of pages) { |
| 75 | + const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root')); |
| 76 | + |
| 77 | + const element = await page.${'$'}('.mynah-chat-prompt-input') |
| 78 | +
|
| 79 | + if(element) { |
| 80 | + |
| 81 | + console.log('Typing /doc in the chat window') |
| 82 | +
|
| 83 | + await page.type('.mynah-chat-prompt-input', '/doc') |
| 84 | + await page.keyboard.press('Enter') |
| 85 | + |
| 86 | + console.log('Attempting to find and click Update an existing README button') |
| 87 | + await findAndClickButton(page, 'Update an existing README', true, 10000) |
| 88 | + console.log('Attempting to find and click Update README to reflect code button') |
| 89 | + await findAndClickButton(page, 'Update README to reflect code', true, 10000) |
| 90 | + console.log('Attempting to find and click Yes button to confirm option') |
| 91 | + await findAndClickButton(page, 'Yes', true, 10000) |
| 92 | + console.log('Waiting for updated README to be generated') |
| 93 | + await new Promise(resolve => setTimeout(resolve, 90000)); |
| 94 | + console.log('Attempting to find and click Accept button') |
| 95 | + await findAndClickButton(page, 'Accept', true, 10000) |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + } finally { |
| 100 | + await browser.close(); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + testNavigation().catch((error) => { |
| 105 | + console.log('Error: Test Failed'); |
| 106 | + console.error(error); |
| 107 | + }); |
| 108 | +
|
| 109 | +""".trimIndent() |
| 110 | + |
| 111 | +// language=TS |
| 112 | +val updateReadmeLatestChangesMakeChangesFlowScript = """ |
| 113 | + |
| 114 | + const puppeteer = require('puppeteer'); |
| 115 | +
|
| 116 | + async function testNavigation() { |
| 117 | + const browser = await puppeteer.connect({ |
| 118 | + browserURL: 'http://localhost:9222' |
| 119 | + }); |
| 120 | +
|
| 121 | + try { |
| 122 | +
|
| 123 | + const pages = await browser.pages(); |
| 124 | + |
| 125 | + for(const page of pages) { |
| 126 | + const contents = await page.evaluate(el => el.innerHTML, await page.${'$'}(':root')); |
| 127 | + |
| 128 | + const element = await page.${'$'}('.mynah-chat-prompt-input'); |
| 129 | + if(element) { |
| 130 | + |
| 131 | + console.log('Typing /doc in the chat window'); |
| 132 | +
|
| 133 | + await page.type('.mynah-chat-prompt-input', '/doc'); |
| 134 | + await page.keyboard.press('Enter'); |
| 135 | +
|
| 136 | + console.log('Attempting to find and click Update an existing README button'); |
| 137 | + await findAndClickButton(page, 'Update an existing README', true, 10000); |
| 138 | + console.log('Attempting to find and click Update README to reflect code button'); |
| 139 | + await findAndClickButton(page, 'Update README to reflect code', true, 10000); |
| 140 | + console.log('Attempting to find and click Yes button to confirm option'); |
| 141 | + await findAndClickButton(page, 'Yes', true, 10000); |
| 142 | + console.log('Waiting for updated README to be generated'); |
| 143 | + await new Promise(resolve => setTimeout(resolve, 90000)); |
| 144 | + console.log('Attempting to find and click Make changes button'); |
| 145 | + await findAndClickButton(page, 'Make changes', true, 10000); |
| 146 | + const makeChangeText = await page.waitForSelector('[placeholder="Describe documentation changes"]'); |
| 147 | + if (!makeChangeText) { |
| 148 | + console.log('Error: Test Failed'); |
| 149 | + console.log('Unable to find placeholder description test in Make Changes flow'); |
| 150 | + } else { |
| 151 | + console.log('Found expected placeholder text for Make Changes flow'); |
| 152 | + console.log('Test Successful'); |
| 153 | + } |
| 154 | +
|
| 155 | + } |
| 156 | + } |
| 157 | +
|
| 158 | + } finally { |
| 159 | + await browser.close(); |
| 160 | + } |
| 161 | + } |
| 162 | +
|
| 163 | + testNavigation().catch((error) => { |
| 164 | + console.log('Error: Test Failed'); |
| 165 | + console.error(error); |
| 166 | + }); |
| 167 | +
|
| 168 | +""".trimIndent() |
| 169 | + |
| 170 | +val updateReadmeLatestChangesConfirmOptionsTestScript = updateReadmeLatestChangesConfirmOptionsScript.plus(findAndClickButtonScript) |
| 171 | +val updateReadmeLatestChangesTestScript = updateReadmeLatestChangesScript.plus(findAndClickButtonScript) |
| 172 | +val updateReadmeLatestChangesMakeChangesFlowTestScript = updateReadmeLatestChangesMakeChangesFlowScript.plus(findAndClickButtonScript) |
0 commit comments