Skip to content

Commit

Permalink
Added puppeteer to allow headless browser execution for successful ap…
Browse files Browse the repository at this point in the history
…p build test
  • Loading branch information
Terézia Slanináková committed Jun 18, 2024
1 parent f343b56 commit 9fcd9ca
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ jobs:
- name: Docker build training, backend, and frontend
run: ./run.sh

- name: Wait for UI to start
run: sleep 10

# Required to see if the app is running
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '14'

- name: Assert UI is running
run: |
curl -f http://localhost:8081 || (echo "The app is not running" && exit 1)
- name: Install Puppeteer
run: npm install puppeteer

- name: Assert API is responding
run: |
curl -f https://localhost:8080/search?query=P69905&offset=0&limit=50 || (echo "The API is not running" && exit 1)
- name: Run Puppeteer script
run: node puppeteer.js
39 changes: 39 additions & 0 deletions .github/workflows/puppeteer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();

try {
// Navigate to your web application
await page.goto('http://localhost:8081/search?q=A0A0C5PVI1&limit=51');

// Perform actions or assertions on the page
const title = await page.title();
console.log('Page title:', title);

// Wait for 5 seconds (adjust as needed) before checking for the element
await page.waitFor(5000);

// Check if the text "A0A0C5PVI1" exists on the page
const textExists = await page.evaluate(() => {
const searchText = 'A0A0C5PVI1';
const elements = Array.from(document.querySelectorAll('*'));
return elements.some(el => el.textContent.includes(searchText));
});

if (textExists) {
console.log('Text "A0A0C5PVI1" found on the page.');
} else {
console.log('Text "A0A0C5PVI1" not found on the page.');
process.exit(1); // Exit with a non-zero status to indicate failure
}

await browser.close();
process.exit(0); // Exit with a zero status to indicate success
} catch (error) {
console.error('Error:', error);
await browser.close();
process.exit(1); // Exit with a non-zero status on error
}
})();

0 comments on commit 9fcd9ca

Please sign in to comment.