Skip to content

Commit

Permalink
try this for playwright test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmimsft committed Jul 13, 2024
1 parent e755fe8 commit 609054e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 15 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,54 @@ jobs:
max_attempts: 3
retry_wait_seconds: 30
command: rad deploy ${{ matrix.path }} ${{ matrix.deployArgs }}
- name: Wait for all pods to be ready
if: steps.gen-id.outputs.RUN_TEST == 'true'
id: wait-for-pods
run: |
namespace="${{ matrix.env }}-${{ matrix.app }}"
label="radapp.io/application=${{ matrix.app }}"
kubectl rollout status deployment -l $label -n $namespace --timeout=90s
# Verify endpoint reachability
- name: Verify endpoint reachability
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.container == ''
run: |
# Extract the endpoint using rad app status
endpoint=$(rad app status -a ${{ matrix.app }} | sed 's/ /\n/g' | grep http)
if [ -z "$endpoint" ]; then
echo "Error: Could not extract endpoint from rad app status"
exit 1
fi
echo "Extracted endpoint: $endpoint"
# Extract hostname and port from the endpoint
hostname=$(echo $endpoint | awk -F[/:] '{print $4}')
port=$(echo $endpoint | awk -F[/:] '{print $5}')
port=${port:-80} # Default to 80 if port is not specified
namespace="${{ matrix.env }}-${{ matrix.app }}"
if [ "$hostname" == "localhost" ]; then
hostname="${{ matrix.app }}.$namespace.svc.cluster.local"
echo "New hostname: $hostname"
fi
echo "Verifying endpoint reachability: $hostname:$port"
# Get the name of an existing pod and use Python for endpoint check
pod_name=$(kubectl get pods -n $namespace -l radapp.io/application=${{ matrix.app }} -o jsonpath='{.items[0].metadata.name}')
if [ -z "$pod_name" ]; then
echo "Error: No pods found for the application"
exit 1
fi
echo "Using pod: $pod_name"
kubectl exec $pod_name -n $namespace -- python3 - <<-EOT
import socket, sys
hostname, port = '$hostname', $port
try:
with socket.create_connection((hostname, port), timeout=10):
print('Endpoint is reachable')
except Exception as e:
print(f'Error: Endpoint is not reachable. {e}')
sys.exit(1)
EOT
- name: Run Playwright Test
if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.uiTestFile != ''
id: run-playwright-test
Expand Down
4 changes: 2 additions & 2 deletions playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default defineConfig({
use: { ...devices["Desktop Safari"] },
},
],
timeout: 1 * 60 * 1000,
timeout: 2 * 60 * 1000,
expect: {
timeout: 30 * 1000,
timeout: 60 * 1000,
},
});
41 changes: 29 additions & 12 deletions playwright/tests/eshop/eshop.app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from "@playwright/test";
import { expect, test } from "@playwright/test";

test("eShop on Containers App Basic UI and Functionality Checks", async ({
page,
Expand All @@ -17,17 +17,34 @@ test("eShop on Containers App Basic UI and Functionality Checks", async ({
let endpoint = process.env.ENDPOINT;
expect(endpoint).toBeDefined();

// Remove quotes from the endpoint if they exist
try {
endpoint = (endpoint as string).replace(/['"]+/g, "");
log(`Navigating to the endpoint: ${endpoint}`);
await page.goto(endpoint);
} catch (error) {
console.error(
`Attempt ${testInfo.retry}: Failed to navigate to the endpoint:`,
error
);
}
// Remove quotes from the endpoint if they exist
try {
endpoint = (endpoint as string).replace(/['"]+/g, "");
log(`Endpoint after removing quotes: ${endpoint}`);
} catch (error) {
console.error(`Error processing the endpoint:`, error);
}

// Check if the endpoint is reachable
try {
const response = await fetch(endpoint);
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
log(`Endpoint is reachable: ${endpoint}`);
} catch (error) {
console.error(`Failed to reach the endpoint:`, error);
return;
}

// Navigate to the endpoint
try {
log(`Navigating to the endpoint: ${endpoint}`);
await page.goto(endpoint);
} catch (error) {
console.error(
`Attempt ${testInfo.retry}: Failed to navigate to the endpoint:`,
error
);
}

// Expect page to have proper URL
log(`Checking the URL: ${endpoint}/catalog`);
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/util/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";

export async function waitForWebApp(url: string | undefined, timeout = 30000) {
export async function waitForWebApp(url: string | undefined, timeout = 60000) {
if (!url) {
throw new Error("URL is not defined");
}
Expand Down

0 comments on commit 609054e

Please sign in to comment.