Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../scripts
File: setup-testing.sh
#!/bin/bash
[0] Fix | Delete
[1] Fix | Delete
# Elementor Testing Environment Setup Script
[2] Fix | Delete
# Usage: npm run setup:testing [--restart]
[3] Fix | Delete
[4] Fix | Delete
set -e # Exit on any error
[5] Fix | Delete
[6] Fix | Delete
# Check if restart flag is provided
[7] Fix | Delete
RESTART_MODE=false
[8] Fix | Delete
if [[ "$1" == "--restart" ]]; then
[9] Fix | Delete
RESTART_MODE=true
[10] Fix | Delete
echo "๐Ÿ”„ Restarting Elementor Testing Environment..."
[11] Fix | Delete
else
[12] Fix | Delete
echo "๐Ÿš€ Setting up Elementor Testing Environment..."
[13] Fix | Delete
fi
[14] Fix | Delete
[15] Fix | Delete
# Colors for output
[16] Fix | Delete
RED='\033[0;31m'
[17] Fix | Delete
GREEN='\033[0;32m'
[18] Fix | Delete
YELLOW='\033[1;33m'
[19] Fix | Delete
NC='\033[0m' # No Color
[20] Fix | Delete
[21] Fix | Delete
# Function to print colored output
[22] Fix | Delete
print_status() {
[23] Fix | Delete
echo -e "${GREEN}โœ… $1${NC}"
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
print_warning() {
[27] Fix | Delete
echo -e "${YELLOW}โš ๏ธ $1${NC}"
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
print_error() {
[31] Fix | Delete
echo -e "${RED}โŒ $1${NC}"
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
# Check prerequisites
[35] Fix | Delete
echo "๐Ÿ” Checking prerequisites..."
[36] Fix | Delete
[37] Fix | Delete
# Check if Docker is running
[38] Fix | Delete
if ! docker info > /dev/null 2>&1; then
[39] Fix | Delete
print_error "Docker is not running. Please start Docker Desktop and try again."
[40] Fix | Delete
exit 1
[41] Fix | Delete
fi
[42] Fix | Delete
print_status "Docker is running"
[43] Fix | Delete
[44] Fix | Delete
# Check if Node.js is installed
[45] Fix | Delete
if ! command -v node > /dev/null 2>&1; then
[46] Fix | Delete
print_error "Node.js is not installed. Please install Node.js 16+ and try again."
[47] Fix | Delete
exit 1
[48] Fix | Delete
fi
[49] Fix | Delete
print_status "Node.js is installed ($(node --version))"
[50] Fix | Delete
[51] Fix | Delete
# Check if npm is installed
[52] Fix | Delete
if ! command -v npm > /dev/null 2>&1; then
[53] Fix | Delete
print_error "npm is not installed. Please install npm and try again."
[54] Fix | Delete
exit 1
[55] Fix | Delete
fi
[56] Fix | Delete
print_status "npm is installed ($(npm --version))"
[57] Fix | Delete
[58] Fix | Delete
# Create .env file if it doesn't exist
[59] Fix | Delete
echo "๐Ÿ“ Setting up environment configuration..."
[60] Fix | Delete
if [ ! -f .env ]; then
[61] Fix | Delete
cat > .env << EOF
[62] Fix | Delete
# WordPress Admin Credentials
[63] Fix | Delete
USERNAME=admin
[64] Fix | Delete
PASSWORD=password
[65] Fix | Delete
[66] Fix | Delete
# WordPress URLs for testing
[67] Fix | Delete
BASE_URL=http://localhost:8888
[68] Fix | Delete
ELEMENTS_REGRESSION_BASE_URL=http://localhost:8889
[69] Fix | Delete
[70] Fix | Delete
# Test Configuration
[71] Fix | Delete
TEST_PARALLEL_INDEX=0
[72] Fix | Delete
[73] Fix | Delete
# Optional: Elementor Experiments (uncomment to enable)
[74] Fix | Delete
# ELEMENTOR_SHOW_HIDDEN_EXPERIMENTS=true
[75] Fix | Delete
[76] Fix | Delete
# Optional: Debug Settings (uncomment to enable)
[77] Fix | Delete
# SCRIPT_DEBUG=true
[78] Fix | Delete
# WP_DEBUG=true
[79] Fix | Delete
EOF
[80] Fix | Delete
print_status "Created .env file with default configuration"
[81] Fix | Delete
else
[82] Fix | Delete
print_warning ".env file already exists, skipping creation"
[83] Fix | Delete
fi
[84] Fix | Delete
[85] Fix | Delete
# Install npm dependencies
[86] Fix | Delete
echo "๐Ÿ“ฆ Installing dependencies..."
[87] Fix | Delete
npm install
[88] Fix | Delete
print_status "Dependencies installed"
[89] Fix | Delete
[90] Fix | Delete
# Clean up any existing containers (always do this for both modes)
[91] Fix | Delete
echo "๐Ÿงน Cleaning up existing containers..."
[92] Fix | Delete
docker stop $(docker ps -q) 2>/dev/null || true
[93] Fix | Delete
docker rm $(docker ps -aq) 2>/dev/null || true
[94] Fix | Delete
[95] Fix | Delete
# Clean storage state files if restarting
[96] Fix | Delete
if [ "$RESTART_MODE" = true ]; then
[97] Fix | Delete
rm -f test-results/.storageState-*.json
[98] Fix | Delete
print_status "Cleaned up containers and storage"
[99] Fix | Delete
else
[100] Fix | Delete
print_status "Cleaned up existing containers"
[101] Fix | Delete
fi
[102] Fix | Delete
[103] Fix | Delete
# Start WordPress environment
[104] Fix | Delete
echo "๐ŸŒ Starting WordPress environment..."
[105] Fix | Delete
npm run start-local-server
[106] Fix | Delete
print_status "WordPress environment started"
[107] Fix | Delete
[108] Fix | Delete
# Wait for WordPress to be ready
[109] Fix | Delete
echo "โณ Waiting for WordPress to be ready..."
[110] Fix | Delete
sleep 10
[111] Fix | Delete
[112] Fix | Delete
# Check if WordPress is accessible
[113] Fix | Delete
max_attempts=30
[114] Fix | Delete
attempt=1
[115] Fix | Delete
while [ $attempt -le $max_attempts ]; do
[116] Fix | Delete
if curl -f http://localhost:8888 > /dev/null 2>&1; then
[117] Fix | Delete
break
[118] Fix | Delete
fi
[119] Fix | Delete
echo "Attempt $attempt/$max_attempts: WordPress not ready yet, waiting..."
[120] Fix | Delete
sleep 2
[121] Fix | Delete
attempt=$((attempt + 1))
[122] Fix | Delete
done
[123] Fix | Delete
[124] Fix | Delete
if [ $attempt -gt $max_attempts ]; then
[125] Fix | Delete
print_error "WordPress failed to start after $max_attempts attempts"
[126] Fix | Delete
exit 1
[127] Fix | Delete
fi
[128] Fix | Delete
[129] Fix | Delete
print_status "WordPress is accessible"
[130] Fix | Delete
[131] Fix | Delete
# Clean WordPress content
[132] Fix | Delete
echo "๐Ÿงน Cleaning WordPress content..."
[133] Fix | Delete
docker exec port8888-cli-1 wp post delete $(docker exec port8888-cli-1 wp post list --post_type=post --format=ids) --force 2>/dev/null || true
[134] Fix | Delete
docker exec port8888-cli-1 wp post delete $(docker exec port8888-cli-1 wp post list --post_type=page --format=ids) --force 2>/dev/null || true
[135] Fix | Delete
docker exec port8888-cli-1 wp comment delete $(docker exec port8888-cli-1 wp comment list --format=ids) --force 2>/dev/null || true
[136] Fix | Delete
[137] Fix | Delete
docker exec port8889-cli-1 wp post delete $(docker exec port8889-cli-1 wp post list --post_type=post --format=ids) --force 2>/dev/null || true
[138] Fix | Delete
docker exec port8889-cli-1 wp post delete $(docker exec port8889-cli-1 wp post list --post_type=page --format=ids) --force 2>/dev/null || true
[139] Fix | Delete
docker exec port8889-cli-1 wp comment delete $(docker exec port8889-cli-1 wp comment list --format=ids) --force 2>/dev/null || true
[140] Fix | Delete
[141] Fix | Delete
print_status "WordPress content cleaned"
[142] Fix | Delete
[143] Fix | Delete
# Install/Fix Elementor plugin
[144] Fix | Delete
echo "๐Ÿ”Œ Setting up Elementor plugin..."
[145] Fix | Delete
[146] Fix | Delete
# Always try to fix mount issues by downloading stable version
[147] Fix | Delete
print_warning "Ensuring Elementor is properly installed..."
[148] Fix | Delete
curl -L -o /tmp/elementor.zip https://downloads.wordpress.org/plugin/elementor.latest-stable.zip
[149] Fix | Delete
unzip -q /tmp/elementor.zip -d /tmp/
[150] Fix | Delete
rm -rf build/*
[151] Fix | Delete
cp -r /tmp/elementor/* build/
[152] Fix | Delete
rm -rf /tmp/elementor.zip /tmp/elementor
[153] Fix | Delete
[154] Fix | Delete
# Activate the plugin
[155] Fix | Delete
docker exec port8888-cli-1 wp plugin activate elementor 2>/dev/null || docker exec port8888-cli-1 wp plugin install elementor --activate
[156] Fix | Delete
docker exec port8889-cli-1 wp plugin activate elementor 2>/dev/null || docker exec port8889-cli-1 wp plugin install elementor --activate
[157] Fix | Delete
[158] Fix | Delete
print_status "Elementor plugin installed and activated"
[159] Fix | Delete
[160] Fix | Delete
# Verify setup
[161] Fix | Delete
echo "๐Ÿ” Verifying setup..."
[162] Fix | Delete
[163] Fix | Delete
# Check WordPress accessibility
[164] Fix | Delete
if ! curl -f http://localhost:8888 > /dev/null 2>&1; then
[165] Fix | Delete
print_error "WordPress on port 8888 is not accessible"
[166] Fix | Delete
exit 1
[167] Fix | Delete
fi
[168] Fix | Delete
[169] Fix | Delete
if ! curl -f http://localhost:8889 > /dev/null 2>&1; then
[170] Fix | Delete
print_error "WordPress on port 8889 is not accessible"
[171] Fix | Delete
exit 1
[172] Fix | Delete
fi
[173] Fix | Delete
[174] Fix | Delete
# Check Elementor plugin
[175] Fix | Delete
if ! docker exec port8888-cli-1 wp plugin list | grep -q "elementor.*active"; then
[176] Fix | Delete
print_error "Elementor plugin is not active on port 8888"
[177] Fix | Delete
exit 1
[178] Fix | Delete
fi
[179] Fix | Delete
[180] Fix | Delete
if ! docker exec port8889-cli-1 wp plugin list | grep -q "elementor.*active"; then
[181] Fix | Delete
print_error "Elementor plugin is not active on port 8889"
[182] Fix | Delete
exit 1
[183] Fix | Delete
fi
[184] Fix | Delete
[185] Fix | Delete
print_status "Setup verification completed successfully"
[186] Fix | Delete
[187] Fix | Delete
echo ""
[188] Fix | Delete
echo "๐ŸŽ‰ Elementor Testing Environment Setup Complete!"
[189] Fix | Delete
echo ""
[190] Fix | Delete
echo "๐Ÿ“‹ What's been set up:"
[191] Fix | Delete
echo " โ€ข WordPress running on http://localhost:8888 and http://localhost:8889"
[192] Fix | Delete
echo " โ€ข Admin credentials: admin / password"
[193] Fix | Delete
echo " โ€ข Elementor plugin installed and activated"
[194] Fix | Delete
echo " โ€ข Environment configured for testing"
[195] Fix | Delete
echo ""
[196] Fix | Delete
echo "๐Ÿš€ Next steps:"
[197] Fix | Delete
echo " โ€ข Run tests: npm run test:elements-regression"
[198] Fix | Delete
echo " โ€ข Run Playwright tests: npm run test:playwright"
[199] Fix | Delete
echo " โ€ข View setup guide: cat TESTING_SETUP.md"
[200] Fix | Delete
echo ""
[201] Fix | Delete
echo "๐Ÿ› ๏ธ Useful commands:"
[202] Fix | Delete
echo " โ€ข Clean restart: npm run restart:testing"
[203] Fix | Delete
echo " โ€ข Start environment: npm run start-local-server"
[204] Fix | Delete
echo " โ€ข View setup guide: cat TESTING_SETUP.md"
[205] Fix | Delete
echo ""
[206] Fix | Delete
[207] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function