博客
关于我
在 selenium IDE 插件中添加上传云端平台的功能
阅读量:279 次
发布时间:2019-03-01

本文共 2135 字,大约阅读时间需要 7 分钟。

          /** 
* 原生 JavaScript 的 Ajax 函数
* @type { {get: Ajax.get, post: Ajax.post}}
*/
const Ajax = {
get: function(url, fn) {
// 使用 XMLHttpRequest 对象进行数据交互
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
// 当请求完成时处理回应
if ((xhr.readyState == 4 && xhr.status == 200) || xhr.status == 304) {
fn.call(this, xhr.responseText);
}
};
xhr.send();
},
post: function(url, data, fn) {
// 使用 XMLHttpRequest 发送 POST 请求
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
// 处理服务器返回的响应
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
fn.call(this, xhr.responseText);
}
};
xhr.send(data);
}
};
export function uploadProject(_project) {
// 将项目对象转换为 JSON 格式
const project = _project.toJS();
const sideJson = JSON.stringify(project);
ModalState.showAlert({
title: '上传云端',
description: sideJson,
confirmLabel: '确定',
cancelLabel: '取消'
}, choseUpload => {
if (choseUpload) {
// 服务器地址配置(示例)
const host = 'https://localhost:9000';
const token = uuidv4();
const data = {
name: project.name,
sideJson: sideJson,
token: token
};
// 发送 POST 请求
Ajax.post(`${host}/uitestcase/upload.api`, JSON.stringify(data), res => {
console.log(res);
});
}
});
}

转载地址:http://nsea.baihongyu.com/

你可能感兴趣的文章
Objective-C实现knight tour骑士之旅算法(附完整源码)
查看>>
Objective-C实现KNN算法(附完整源码)
查看>>
Objective-C实现koch snowflake科赫雪花算法(附完整源码)
查看>>
Objective-C实现KPCA(附完整源码)
查看>>
Objective-C实现KruskalMST最小生成树的算法(附完整源码)
查看>>
Objective-C实现kth order statistick阶统计量算法(附完整源码)
查看>>
Objective-C实现Lempel-Ziv压缩算法(附完整源码)
查看>>
Objective-C实现LongestIncreasingSubsequence最长递增子序列算法(附完整源码)
查看>>
Objective-C实现Lower-Upper Decomposition上下分解算法(附完整源码)
查看>>
Objective-C实现LRU 缓存算法(附完整源码)
查看>>
Objective-C实现LRU缓存(附完整源码)
查看>>
Objective-C实现lstm prediction预测算法(附完整源码)
查看>>
Objective-C实现lucas数列算法(附完整源码)
查看>>
Objective-C实现Luhn (Mod 10)Algorithm算法(附完整源码)
查看>>
Objective-C实现MAC桌面暗水印(附完整源码)
查看>>
Objective-C实现matrix exponentiation矩阵求幂算法(附完整源码)
查看>>
Objective-C实现MatrixMultiplication矩阵乘法算法 (附完整源码)
查看>>
Objective-C实现max non adjacent sum最大非相邻和算法(附完整源码)
查看>>
Objective-C实现max subarray sum最大子数组和算法(附完整源码)
查看>>
Objective-C实现MaximumSubarray最大子阵列(Brute Force蛮力解决方案)算法(附完整源码)
查看>>