我有以下 Groovy 脚本,我试图在其中获取目录名和文件名:
File dir = new File("C://Users//avidCoder//Project")
log.info dir //Fetching the directory path
String fileName = "Demo_Data" + ".json"
log.info fileName //Fetching the file name
String fullpath = dir + "\\" + fileName
log.info fullpath //Fetching the full path gives error
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,出现以下异常:
“java.io.File.plus() 适用于参数类型”
为什么创建fullpath变量会抛出这个异常?
我有一些 API 需要访问令牌才能获取响应。postman我们通过OAuth 2.0提供客户端用户名和密码来获取访问令牌。以类似的方式,我想获取新的访问令牌。
这是迄今为止我尝试过的示例代码。
import java.io.*;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
import java.lang.reflect.Type;
import javax.net.ssl.HttpsURLConnection;
// Google Gson Libraries used for Json Parsing
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class AuthGoogle {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String grantType = "client_credentials";
String applicationID = "application";
String username = "username";
String password = "password";
String url = "url_link";
HttpsURLConnection httpConn …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成 html 格式的灯塔报告,但无法这样做。
我收到以下错误:
找不到模块“lighthouse/lighthouse-core/report/report-generator”
我使用以下链接来配置我的灯塔测试:-
https://atomfrede.gitlab.io/2021/04/automated-frontend-perfomance-test-with-lighthouse-for-jhipster/
不确定,实际上是什么错误,我一次又一次尝试安装灯塔。尽管如此,还是没有运气。
npm install --save-dev lighthouse
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的代码:-
const { lighthouse, pa11y, prepareAudit } = require('cypress-audit');
const fs = require('fs');
const ReportGenerator = require('lighthouse/lighthouse-core/report/report-generator');
module.exports = (on, config) => {
on('before:browser:launch', (browser, launchOptions) => {
prepareAudit(launchOptions);
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--disable-gpu');
return launchOptions;
}
});
on('task', {
lighthouse: lighthouse((lighthouseReport) => {
fs.writeFileSync('build/cypress/lhreport.html',
ReportGenerator.generateReport(lighthouseReport.lhr, 'html'));
}),
pa11y: pa11y(),
});
};
Run Code Online (Sandbox Code Playgroud) 在 Cypress 中 - cypress 中的first() 和last() 函数选择或单击DOM 内的第一个和最后一个元素。但是如果我想单击第二个和第三个元素怎么办?
目前我正在使用下面的代码来单击第一个和最后一个元素:-
const fs = cy.get('div.outer-circle').first();
fs.click();
const ls = cy.get('div.outer-circle').last();
ls.click();
Run Code Online (Sandbox Code Playgroud)
我试图单击第二个元素。为此,我还使用了 next() 函数。
const ss = cy.get('div.outer-circle').next();
ss.click({multiple: true, force: true});
Run Code Online (Sandbox Code Playgroud)
但不幸的是,它开始点击所有元素。
有人可以在这里提出建议吗?如何采用这种方法,我对 Cypress 工具还很陌生。
我正在尝试仅使用特殊字符来创建大小为5的字符串-
〜`!@#$%^&*()-_ = + [{]} \ |;:\'\“,<。> /?
其中也包括空间。
下面是我尝试过的代码行:
public static String randomSpecialCharacterString() {
char[] possibleCharacters = (new String("~`!@ # $ %^&*()-_=+[{]}\\|;:\'\",<.>/?")).toCharArray();
String randomStr = RandomStringUtils.random( 5, 0, possibleCharacters.length-1, false, false, possibleCharacters, new SecureRandom());
return randomStr;
}
Run Code Online (Sandbox Code Playgroud)
但是,它不会返回非重复的String。而且,应该返回带空格的String。
例如- @# ?/和!)( +
我已经浏览了所有可能的重复项。
我想使用JsonBuilder创建下面的JSON.
"isOut": false,
"baleRun": {
"incData": true,
"appendCricket": [{
"min": 10,
"max": 32,
"price": "10"
}]
}
Run Code Online (Sandbox Code Playgroud)
我试过下面的代码来创建它: -
import groovy.json.*
def builder = new JsonBuilder()
def root = builder.baleRun{
incData true
builder.appendCricket [
{
min 10
max 32
price "10000"
}
]
}
Run Code Online (Sandbox Code Playgroud)
得到以下错误: -
groovy.lang.MissingPropertyException: No such property: appendCricket for
class: groovy.json.JsonBuilder error.
Run Code Online (Sandbox Code Playgroud)
知道如何制作这个吗?