Nuestro conocimiento compartido. Nuestro tesoro compartido. Wikipedia.
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 document.addEventListener('DOMContentLoaded', function() {2  document.getElementById('welcome-modal').classList.remove('hidden');3 });4 5 function closeWelcomeModal() {6  document.getElementById('welcome-modal').classList.add('hidden');7 }8 9 function addVariable() {10  const list = document.getElementById('elements-list');11  const div = document.createElement('div');12  div.classList.add('element', 'bg-white', 'p-4', 'rounded-lg', 'shadow-md', 'flex', 'items-center', 'space-x-4');13  div.innerHTML = `14  <span class="text-gray-700">Variable</span>15  <input type="text" placeholder="Nombre" class="flex-1 p-2 border border-gray-300 rounded" />16  <input type="text" placeholder="Valor" class="flex-1 p-2 border border-gray-300 rounded" />17  <button type="button" onclick="removeElement(this)" class="text-red-500">x</button>18  `;19  list.appendChild(div);20 }21 22 function addRequest() {23  const list = document.getElementById('elements-list');24  const div = document.createElement('div');25  div.classList.add('element', 'bg-white', 'p-4', 'rounded-lg', 'shadow-md', 'flex', 'items-center', 'space-x-4');26  div.innerHTML = `27  <span class="text-gray-700">Request</span>28  <select class="flex-1 p-2 border border-gray-300 rounded">29  <option>GET</option>30  <option>POST</option>31  <option>PUT</option>32  <option>DELETE</option>33  </select>34  <input type="text" placeholder="URL" class="flex-1 p-2 border border-gray-300 rounded" />35  <textarea placeholder="Headers" class="flex-1 p-2 border border-gray-300 rounded"></textarea>36  <textarea placeholder="Body" class="flex-1 p-2 border border-gray-300 rounded"></textarea>37  <button type="button" onclick="removeElement(this)" class="text-red-500">x</button>38  `;39  list.appendChild(div);40 }41 42 function addAssert() {43  const list = document.getElementById('elements-list');44  const div = document.createElement('div');45  div.classList.add('element', 'bg-white', 'p-4', 'rounded-lg', 'shadow-md', 'space-y-4');46  div.innerHTML = `47  <span class="text-gray-700">Assert</span>48  <div class="flex items-center space-x-4">49  <input type="text" placeholder="Referencia" class="flex-1 p-2 border border-gray-300 rounded assert-reference" list="references-datalist"/>50  <datalist id="references-datalist">51  <option value="response.status">52  <option value="response.headers.Content-Type">53  <option value="response.body.user.name">54  <!-- Añadir más opciones dinámicamente -->55  </datalist>56  <select class="flex-1 p-2 border border-gray-300 rounded" onchange="updateAssertInput(this)">57  <option value="equals">Igual a</option>58  <option value="not_equals">Distinto a</option>59  <option value="in_list">En lista</option>60  <option value="not_in_list">No en lista</option>61  </select>62  <input type="text" placeholder="Valor" class="flex-1 p-2 border border-gray-300 rounded assert-value" />63  <button type="button" onclick="removeElement(this)" class="text-red-500">x</button>64  </div>65  `;66  list.appendChild(div);67 }68 69 function addSleep() {70  const list = document.getElementById('elements-list');71  const div = document.createElement('div');72  div.classList.add('element', 'bg-white', 'p-4', 'rounded-lg', 'shadow-md', 'flex', 'items-center', 'space-x-4');73  div.innerHTML = `74  <span class="text-gray-700">Sleep</span>75  <input type="number" placeholder="Segundos" class="flex-1 p-2 border border-gray-300 rounded" />76  <button type="button" onclick="removeElement(this)" class="text-red-500">x</button>77  `;78  list.appendChild(div);79 }80 81 function removeElement(element) {82  element.parentElement.parentElement.remove();83 }84 85 function saveTest() {86  const elements = [];87  const listItems = document.getElementById('elements-list').children;88  for (let i = 0; i < listItems.length; i++) {89  const element = listItems[i];90  const type = element.querySelector('span').textContent;91  if (type === 'Variable') {92  const name = element.children[1].value;93  const value = element.children[2].value;94  if (name && value) {95  elements.push({ type, name, value });96  } else {97  alert('Please fill out both name and value for all variables.');98  return;99  }100  } else if (type === 'Request') {101  const method = element.children[1].value;102  const url = element.children[2].value;103  const headers = element.children[3].value;104  const body = element.children[4].value;105  if (method && url) {106  elements.push({ type, method, url, headers, body });107  } else {108  alert('Please fill out method and URL for all requests.');109  return;110  }111  } else if (type === 'Assert') {112  const assertType = element.children[2].value;113  const reference = element.children[1].value;114  const value = element.children[3].value;115  if (reference && value) {116  elements.push({ type, assertType, reference, value });117  } else {118  alert('Please fill out reference and value for all asserts.');119  return;120  }121  } else if (type === 'Sleep') {122  const seconds = element.children[1].value;123  if (seconds) {124  elements.push({ type, seconds });125  } else {126  alert('Please fill out the number of seconds for all sleeps.');127  return;128  }129  }130  }131  console.log('Elements:', elements);132  alert('Test saved!');133 }134 135 function updateAssertInput(select) {136  const valueInput = select.parentElement.querySelector('.assert-value');137  if (select.value === 'in_list' || select.value === 'not_in_list') {138  valueInput.placeholder = 'Valores (separados por comas)';139  } else {140  valueInput.placeholder = 'Valor';141  }142 }143 
Enlace
El enlace para compartir es: