113 lines
		
	
	
		
			No EOL
		
	
	
		
			4 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			No EOL
		
	
	
		
			4 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| # Run certificate-specific Playwright tests
 | |
| # This script runs Playwright tests for certificate functionality
 | |
| 
 | |
| # Colors for output
 | |
| GREEN='\033[0;32m'
 | |
| RED='\033[0;31m'
 | |
| YELLOW='\033[1;33m'
 | |
| BLUE='\033[0;34m'
 | |
| NC='\033[0m' # No Color
 | |
| 
 | |
| # Change to the project root directory
 | |
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 | |
| cd "$SCRIPT_DIR/.." || exit 1
 | |
| echo "Changed working directory to: $(pwd)"
 | |
| 
 | |
| # Display banner
 | |
| echo -e "${BLUE}============================================${NC}"
 | |
| echo -e "${BLUE}      Certificate Playwright Tests         ${NC}"
 | |
| echo -e "${BLUE}============================================${NC}"
 | |
| 
 | |
| # Load environment variables
 | |
| if [ -f ./.env ]; then
 | |
|   echo "Loading environment variables from .env"
 | |
|   source ./.env
 | |
| else
 | |
|   echo -e "${RED}Error: .env file not found!${NC}"
 | |
|   echo "Make sure you have a .env file with the required environment variables"
 | |
|   exit 1
 | |
| fi
 | |
| 
 | |
| # Verify plugin is activated
 | |
| echo -e "${YELLOW}Verifying plugin activation...${NC}"
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && wp plugin is-active hvac-community-events --allow-root"
 | |
| 
 | |
| if [ $? -ne 0 ]; then
 | |
|   echo -e "${YELLOW}Plugin not active. Activating hvac-community-events...${NC}"
 | |
|   sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && wp plugin activate hvac-community-events --allow-root"
 | |
|   
 | |
|   if [ $? -ne 0 ]; then
 | |
|     echo -e "${RED}Failed to activate plugin. Cannot continue.${NC}"
 | |
|     exit 1
 | |
|   fi
 | |
|   
 | |
|   # Flush rewrite rules
 | |
|   echo -e "${YELLOW}Flushing rewrite rules...${NC}"
 | |
|   sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && wp rewrite flush --hard --allow-root"
 | |
| else
 | |
|   echo -e "${GREEN}Plugin is active.${NC}"
 | |
| fi
 | |
| 
 | |
| # Check if test user exists
 | |
| echo -e "${YELLOW}Checking test user...${NC}"
 | |
| USER_EXISTS=$(sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && wp user get test_trainer --field=ID --allow-root 2>/dev/null || echo 'notfound'")
 | |
| 
 | |
| if [ "$USER_EXISTS" == "notfound" ]; then
 | |
|   echo -e "${YELLOW}Test user not found. Creating test user...${NC}"
 | |
|   # Run the setup script
 | |
|   ./bin/setup-staging-test-users.sh
 | |
| else
 | |
|   echo -e "${GREEN}Test user found with ID: $USER_EXISTS${NC}"
 | |
| fi
 | |
| 
 | |
| # Clear cache if needed
 | |
| echo -e "${YELLOW}Clearing cache...${NC}"
 | |
| sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "cd $UPSKILL_STAGING_PATH && wp cache flush --allow-root"
 | |
| 
 | |
| # Get UI mode from args
 | |
| UI_MODE=""
 | |
| if [[ "$1" == "--headed" ]]; then
 | |
|   UI_MODE="--headed"
 | |
|   echo -e "${YELLOW}Running with UI visible${NC}"
 | |
| else
 | |
|   echo -e "${YELLOW}Running in headless mode${NC}"
 | |
| fi
 | |
| 
 | |
| # Get debug mode from args
 | |
| DEBUG_MODE=""
 | |
| if [[ "$1" == "--debug" || "$2" == "--debug" ]]; then
 | |
|   DEBUG_MODE="--debug"
 | |
|   echo -e "${YELLOW}Running in debug mode${NC}"
 | |
| fi
 | |
| 
 | |
| # Run the test
 | |
| echo -e "${YELLOW}Running certificate tests...${NC}"
 | |
| echo -e "${YELLOW}$ npx playwright test tests/e2e/certificate-basic.spec.ts $UI_MODE $DEBUG_MODE${NC}"
 | |
| 
 | |
| # Start the test
 | |
| npx playwright test tests/e2e/certificate-basic.spec.ts $UI_MODE $DEBUG_MODE
 | |
| 
 | |
| # Check test result
 | |
| TEST_RESULT=$?
 | |
| if [ $TEST_RESULT -eq 0 ]; then
 | |
|   echo -e "${GREEN}✓ Certificate tests completed successfully!${NC}"
 | |
| else
 | |
|   echo -e "${RED}✗ Certificate tests failed with exit code $TEST_RESULT${NC}"
 | |
| fi
 | |
| 
 | |
| # Show report location
 | |
| echo -e "${YELLOW}Test artifacts are available in the test-results directory${NC}"
 | |
| echo -e "${YELLOW}To view HTML report, run: npx playwright show-report${NC}"
 | |
| 
 | |
| # Offer to run the standalone Node.js test for comparison
 | |
| echo -e "\n${YELLOW}Would you like to run the standalone Node.js test for comparison? (y/n)${NC}"
 | |
| read -r RUN_STANDALONE
 | |
| 
 | |
| if [[ "$RUN_STANDALONE" == "y" ]]; then
 | |
|   echo -e "${YELLOW}Running standalone certificate test...${NC}"
 | |
|   node bin/certificate-test.js
 | |
| fi
 | |
| 
 | |
| exit $TEST_RESULT |