我在尝试为我的后调用创建一个集成测试时遇到了麻烦,该测试接受一个具有其他值的视图模型,一个 IFormFile,它使此调用从 application/json 到 multipart/form-data
我的 IntegrationSetup 类
protected static IFormFile GetFormFile()
{
byte[] bytes = Encoding.UTF8.GetBytes("test;test;");
var file = new FormFile(
baseStream: new MemoryStream(bytes),
baseStreamOffset: 0,
length: bytes.Length,
name: "Data",
fileName: "dummy.csv"
)
{
Headers = new HeaderDictionary(),
ContentType = "text/csv"
};
return file;
}
Run Code Online (Sandbox Code Playgroud)
我的测试方法
public async Task CreateAsync_ShouldReturnId()
{
//Arrange
using var content = new MultipartFormDataContent();
var stringContent = new StringContent(
JsonConvert.SerializeObject(new CreateArticleViewmodel
{
Title = "viewModel.Title",
SmallParagraph = "viewModel.SmallParagraph",
Url = "viewModel.Url",
Image = GetFormFile()
}), …Run Code Online (Sandbox Code Playgroud) c# integration-testing web-api-testing asp.net-core asp.net-core-webapi
当使用带有PhpBrowser驱动程序的REST模块通过代码接收测试发出请求时,没有数据和文件通过Silex应用程序。
// ApiTester $I
$I->wantTo('Submit files');
// prepare:
$data = ['key' => 'value'];
$files = [
'file_key' => 'path/to/file.doc',
'file2_key' => 'path/to/file2.doc'
];
// act:
$I->haveHttpHeader('Content-Type', 'multipart/form-data');
$I->sendPOST('/attachments/', $data, $files);
Run Code Online (Sandbox Code Playgroud)
I have http header "Content-Type","multipart/form-data"
I send post "/attachments/",{"key":"value"},{"file_key":"/path/to/file/...}
[Request] POST http://localhost/attachments/ {"key":"value"}
[Request Headers] {"Content-Type":"multipart/form-data"}
[Page] http://localhost/attachments/
[Response] 400
[Request Cookies] []
[Response Headers] {"Date":["Tue, 25 Oct 2016 09:15:31 GMT"],"Server":["Apache/2.4.10 (Debian)"],"Cache-Control":["no-cache"],"Access-Control-Allow-Origin":["*"],"Access-Control-Allow-Headers":["Content-Type, Authorization"],"Access-Control-Allow-Methods":["GET,PATCH,PUT,POST,HEAD,DELETE,OPTIONS"],"Content-Length":["1235"],"Connection":["close"],"Content-Type":["application/json"]}
[Response] {"status":400,"meta":{"time":"2016-10-25 09:15:31"},"title":"Invalid Request","errors":"No data received","details":{"error_class":"Symfony\Component\HttpKernel\Exception\BadRequestHttpException"
Run Code Online (Sandbox Code Playgroud)
该测试可与Silex驱动程序一起使用,但在CI服务器上将不可选。我们还检查了Postman,API路由按预期工作,文件已发送且一切正常。
使用放心的 jar 发出 GET api 请求时,我的程序在作为 TestNg 运行时抛出以下错误
输出:
java.lang.NoClassDefFoundError: io/restassured/path/json/mapper/factory/JsonbObjectMapperFactory
at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
at io.restassured.RestAssured.<clinit>(RestAssured.java:421)
at SimpleGetTest.GetWeatherDetails(SimpleGetTest.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: io.restassured.path.json.mapper.factory.JsonbObjectMapperFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown …Run Code Online (Sandbox Code Playgroud) 我正在使用 RestSharp 发出包含 JSON 正文的 POST 请求。但我收到错误请求错误。
因为我已经[]在""JSON 中决定使用 Newtonsoft.Json 。在使用它之前,我什至看不到正在形成的 JSON 请求。
我愿意尝试MS httpwebrequest作为替代方案。
restClient = new RestClient();
restRequest = new RestRequest(ApiUrl, Method.POST, DataFormat.Json);
var myObject = "{ \"target\" : \"[5,5]\", \"lastseen\" : \"1555459984\" }";
var json = JsonConvert.SerializeObject(myObject);
restRequest.AddParameter("application/json", ParameterType.RequestBody);
restRequest.AddJsonBody(json);
Run Code Online (Sandbox Code Playgroud)
请注意,我正在尝试将 JSON 卷曲转换为 C#。请看下面:
curl -H 'Content-Type: application/json' -X POST -d '{ "target" : [5, 5], "lastseen" : "1555459984", "previousTargets" : [ [1, 0], [2, 2], [2, 3] ] }' http://santized/santized/santized
我想断言从响应中收到的总数。
这是我的代码:
cy.request({
method:'GET',
url:'https://ibis-qa.droicelabs.us/api/practice/orders/?q=&limit=100',
failOnStatusCode: false,
headers:{
accept: "application/json"
}
}).then(Response => {
let body = JSON.parse(JSON.stringify(Response.body))
cy.log(body)
expect(body).has.property('count','27')
})
Run Code Online (Sandbox Code Playgroud)
这是我遇到的错误
我想从 API 响应中获取订单 ID。当我单击“创建订单”按钮时,它将发送 POST API 请求并返回我想要保存在 JSON 文件中的 ID。
这是我的订单创建代码。
cy.clickOnElement(practicePageSelectors.CreateOrder).click(); // click on add Rx button
cy.readFile('cypress/fixtures/Data.json').then((profile) => {
cy.searchPatients(practicePageSelectors.searchPatient1, profile.Patient_fullName);
})
cy.searchDoctors(); // search for the doctor
cy.clickOnElementUsingXpath(practicePageSelectors.nextButtonId); // click on the next button
cy.clickOnElement(practicePageSelectors.createOnetimeOrder)
cy.searchMedicine() //search for Medicine
cy.clickOnElementUsingXpathfirst(practicePageSelectors.addMedicine); // click on add button
cy.clickOnElementUsingText(practiceData.paymentButtonName, practiceData.buttonTag); // click on skip payment button
cy.clickOnElementUsingXpath(practicePageSelectors.submit_CreateOrderButton)
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情
cy.intercept({
method: 'POST',
url: 'https://ibis-dev.droicelabs.us/api/dispenser/orders/',
}).then((responce)=>{
let body = JSON.parse(responce.body)
cy.log(body)
})
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用intercept。请指导我
我是赛普拉斯的新手。我想知道是否有任何方法可以通过用 cypress 测试中以编程方式生成的值替换 JSON 文件的值来生成动态有效负载。我们在放心中所做的事情是替换 JSON 文件的 %s。我在网上搜索了很多但没有找到。类似的一些问题是这对我不起作用 我想将动态 json 正文传递给 cypress request() 函数并定义有效负载值
我有以下 json 文件
{
"name": "Ganesh vishal kumar",
"gender": "Male",
"email": "ganesh.kumar234@test.org",
"status": "active"
}
Run Code Online (Sandbox Code Playgroud)
我想要一个动态 JSON 文件装置。在下面的测试中,我以编程方式生成电子邮件 ID 并直接在 JSON 正文中使用它。这里我想使用JSON文件fixture
it('first post test', () => {
var pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var emailId = "";
for (var x = 0; x < 10; x++) {
emailId = emailId + pattern.charAt(Math.floor(Math.random() * pattern.length));
}
emailId = emailId + '@test.org'
cy.request({
method: 'POST',
url: 'https://gorest.co.in/public/v2/users',
body: { …Run Code Online (Sandbox Code Playgroud) cypress ×3
c# ×2
json ×2
asp.net-core ×1
codeception ×1
jar ×1
java ×1
phpunit ×1
post ×1
rest ×1
rest-assured ×1
restsharp ×1
testng ×1
typescript ×1