小编Woj*_*k T的帖子

将过滤的cmd命令输出存储在变量中

我试图将cmd命令的输出存储为python中的变量.为了实现这一点,我正在使用os.system()os.system()只是运行过程,它不捕获输出.

import os


PlatformName = os.system("adb shell getprop | grep -e 'bt.name'")
DeviceName = os.system("adb shell getprop | grep -e '.product.brand'")
DeviceID = os.system("adb shell getprop | grep -e 'serialno'")
Version = os.system("adb shell getprop | grep -e 'version.release'")

print(PlatformName)
print(DeviceName)
print(DeviceID)
print(Version)
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用该subprocess模块.

import subprocess
import os


PlatformName = subprocess.check_output(["adb shell getprop | grep -e 'bt.name'"])
DeviceName = subprocess.check_output(["adb shell getprop | grep -e '.product.brand'"])
DeviceID = subprocess.check_output(["adb shell getprop | grep -e …
Run Code Online (Sandbox Code Playgroud)

python variables cmd

7
推荐指数
1
解决办法
462
查看次数

机器人框架更有效的"睡眠"方式

我正在使用Robot Framework,

目前我有5-10个测试用例,我点击按钮后使用sleep等待页面完全加载,

*** Variables ***

${Name} =  example name
${Next_Button} =  xpath=//*[@id="app"]/div/div[1]/div[3]/div/div/div[1]/div[2]/div/div/div/button[2]

*** Keywords ***
Open Tab
    Click Element  xpath=//*[@id="app"]/div/div[1]/div[1]/div[2]/nav/ul/li[2]/a
    Sleep  5s

Open Details
    Click Element  xpath=//*[@id="app"]/div/div[1]/div[3]/div/div/div[1]/div[2]/div/div[1]/img
    sleep  5s


Navigate to Room Details
    click button   xpath=//*[@id="app"]/div/div[1]/div[3]/div/div/div[1]/div[2]/div/div/button
    click button  ${Next_Button}
    click button  ${Next_Button}
    sleep  3s
Run Code Online (Sandbox Code Playgroud)

当我的测试增加到100-200时,运行它们将花费大量时间,

什么是更有效的使用Sleep的方法,或者是一个可以用于大量测试的不同关键字.我的网络应用程序从1-5秒加载.

testing selenium keyword robotframework

3
推荐指数
1
解决办法
4900
查看次数

RobotFramework - 同时处理2个浏览器选项卡并测试它们

我有这个问题,我需要测试我的Web应用程序的功能,打开2个选项卡,并检查我是否更新了选项卡1选项卡2刷新,我试图使用Press key关键字完成此操作.

我的目标是使用Ascii编号CTRL+T来打开一个新选项卡,打开一个新的浏览器窗口,而不是一个新选项卡,我使用的是Chrome的最新版本.

我也试图使用,\\09 但这给了我相同的结果

Press Key  tag=body   \\20
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用Select Window MAIN关键字返回窗口, 但这不起作用.

问:如何可以打开在同一时间2个标签和使用测试它们RobotFrameworkSeleniumLibrary

testing selenium google-chrome robotframework

1
推荐指数
1
解决办法
1304
查看次数

格式化json String并将其传递给具有参数的主体给出错误

我正在尝试使用RestSharp创建一个post请求.

我有以下字符串

"{ \"name\": \"string\", \"type\": \"string\", \"parentId\": \"string\", \"Location\": [ \"string\" ]}"
Run Code Online (Sandbox Code Playgroud)

我需要将它传递到json主体发送POST请求我正在尝试以下.

public IRestResponse PostNewLocation(string Name, string Type, Nullable<Guid> ParentId, string Locatations)
{
  string NewLocation = string.Format("{ \"name\": \"{0}\", \"type\": \"{1}\", \"parentId\": \"{2}\", \"Location\": [ \"{3}\" ]}", Name, Type, ParentId, Location);
  var request = new RestRequest(Method.POST);
  request.Resource = string.Format("/Sample/Url");
  request.AddParameter("application/json", NewLocation, ParameterType.RequestBody);
  IRestResponse response = Client.Execute(request);
}
Run Code Online (Sandbox Code Playgroud)

而错误

Message: System.FormatException : Input string was not in a correct format.
Run Code Online (Sandbox Code Playgroud)

如何格式化上面的字符串以将其传递到json正文?

我的测试在这一行失败了

string NewLocation = string.Format("{ \"name\": \"{0}\", \"type\": …
Run Code Online (Sandbox Code Playgroud)

c# api restsharp

1
推荐指数
1
解决办法
653
查看次数

以字符串形式返回响应

我正在尝试使用 RestSharp 从 POST 请求返回字符串响应。

这就是我正在尝试的

public IRestResponse PostNewLocation(string Name, string Type, Nullable<Guid> ParentId, string Location)
{
    object tmp = new
    {
        name = Name,
        type = Type,
        parentId = ParentId,
        Location = Location
    };
    string json = JsonConvert.SerializeObject(tmp);

    var Client = new RestClient();
    Client.BaseUrl = new Uri(BaseURL);
    var request = new RestRequest(Method.POST);
    request.Resource = string.Format("/Sample/URL?");
    request.AddParameter("application/json", json, ParameterType.RequestBody);
    IRestResponse response = Client.Execute(request);

    Console.Write(response.Content);

    if (!IsReturnedStatusCodeOK(response))
    {
        throw new HttpRequestException("Request issue -> HTTP code:" + response.StatusCode);
    }

    return response.Content;
} …
Run Code Online (Sandbox Code Playgroud)

c# api restsharp

1
推荐指数
1
解决办法
6971
查看次数

TFS 2017 - 如何使用代码覆盖率运行构建?

嗨,我正在尝试使用代码覆盖运行构建,我正在使用Visual Stuido 2017企业我试图在VS中启用代码覆盖,但如果我在团队资源管理器中单击编辑构建定义,它将在TFS中打开构建定义.

visual-studio visual-studio-2017 tfs2017

0
推荐指数
1
解决办法
3242
查看次数

把Double"""放入一个字符串中

我有这个json

object tmp = new
            {
                name = Name,
                type = Type,
                parentId = ParentId,
                Location= string.Format("[\"{0}\"]" ,Location1)
            };
            string json = JsonConvert.SerializeObject(tmp);
Run Code Online (Sandbox Code Playgroud)

这个字符串正在解决这个问题

string Location = string.Format("[\"{0}\"]" ,Location1)
Run Code Online (Sandbox Code Playgroud)

结果是

{...,"Location":"[\"Location5201\"]"}
Run Code Online (Sandbox Code Playgroud)

如果我摆脱了 \

然后输出是

{...,"Location":"[Location5201]"}
Run Code Online (Sandbox Code Playgroud)

我想要的输出应该是

{...,"Location":["Location5201"]}
Run Code Online (Sandbox Code Playgroud)

我怎么能把""上面的字符串放进去?

c# string

0
推荐指数
1
解决办法
65
查看次数