1 document.addEventListener('DOMContentLoaded', function() {2 // Mostrar el modal de bienvenida al cargar la página3 document.getElementById('welcome-modal').classList.remove('hidden');4 });5 6 function closeWelcomeModal() {7 document.getElementById('welcome-modal').classList.add('hidden');8 }9 10 function addVariable() {11 const list = document.getElementById('elements-list');12 const div = document.createElement('div');13 div.classList.add('element', 'bg-white', 'p-4', 'rounded-lg', 'shadow-md', 'flex', 'items-center', 'space-x-4');14 div.innerHTML = `15 <span class="text-gray-700">Variable</span>16 <input type="text" placeholder="Nombre" class="flex-1 p-2 border border-gray-300 rounded" />17 <input type="text" placeholder="Valor" class="flex-1 p-2 border border-gray-300 rounded" />18 <button type="button" onclick="removeElement(this)" class="text-red-500">x</button>19 `;20 list.appendChild(div);21 }22 23 function addRequest() {24 const list = document.getElementById('elements-list');25 const div = document.createElement('div');26 div.classList.add('element', 'bg-white', 'p-4', 'rounded-lg', 'shadow-md', 'flex', 'items-center', 'space-x-4');27 div.innerHTML = `28 <span class="text-gray-700">Request</span>29 <select class="flex-1 p-2 border border-gray-300 rounded">30 <option>GET</option>31 <option>POST</option>32 <option>PUT</option>33 <option>DELETE</option>34 </select>35 <input type="text" placeholder="URL" class="flex-1 p-2 border border-gray-300 rounded" />36 <textarea placeholder="Headers" class="flex-1 p-2 border border-gray-300 rounded"></textarea>37 <textarea placeholder="Body" class="flex-1 p-2 border border-gray-300 rounded"></textarea>38 <button type="button" onclick="removeElement(this)" class="text-red-500">x</button>39 `;40 list.appendChild(div);41 }42 43 function addAssert() {44 const list = document.getElementById('elements-list');45 const div = document.createElement('div');46 div.classList.add('element', 'bg-white', 'p-4', 'rounded-lg', 'shadow-md', 'flex', 'items-center', 'space-x-4');47 div.innerHTML = `48 <span class="text-gray-700">Assert</span>49 <input type="text" placeholder="Expresión" class="flex-1 p-2 border border-gray-300 rounded" />50 <button type="button" onclick="removeElement(this)" class="text-red-500">x</button>51 `;52 list.appendChild(div);53 }54 55 function removeElement(element) {56 element.parentElement.remove();57 }58 59 function saveTest() {60 const elements = [];61 const listItems = document.getElementById('elements-list').children;62 for (let i = 0; i < listItems.length; i++) {63 const element = listItems[i];64 const type = element.querySelector('span').textContent;65 if (type === 'Variable') {66 const name = element.children[1].value;67 const value = element.children[2].value;68 if (name && value) {69 elements.push({ type, name, value });70 } else {71 alert('Please fill out both name and value for all variables.');72 return;73 }74 } else if (type === 'Request') {75 const method = element.children[1].value;76 const url = element.children[2].value;77 const headers = element.children[3].value;78 const body = element.children[4].value;79 if (method && url) {80 elements.push({ type, method, url, headers, body });81 } else {82 alert('Please fill out method and URL for all requests.');83 return;84 }85 } else if (type === 'Assert') {86 const expression = element.children[1].value;87 if (expression) {88 elements.push({ type, expression });89 } else {90 alert('Please fill out expression for all asserts.');91 return;92 }93 }94 }95 console.log('Elements:', elements);96 alert('Test saved!');97 }98
Enlace
El enlace para compartir es: