• 常用的 Chrome 插件 at August 31, 2019
  • package com.zdlh.suite;

    import com.fasterxml.jackson.core.type.TypeReference;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
    import org.junit.Rule;
    import org.junit.Test;
    import org.junit.rules.ErrorCollector;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;

    import java.io.File;
    import java.io.IOException;
    import java.util.List;

    import static org.hamcrest.CoreMatchers.equalTo;

    @RunWith(Parameterized.class)
    public class ParameterDataYaml {

    @Rule
    public ErrorCollector collector = new ErrorCollector();

    @Parameterized.Parameters
    public static List<TestDataYaml> dataYaml() throws IOException {
    return readFromYaml();
    }

    @Parameterized.Parameter
    public TestDataYaml data;

    public static List<TestDataYaml> readFromYaml() throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    List<TestDataYaml> data = mapper.readValue(
    new File("/Users/ywj/workspace/api_test/data/testdata.yaml"),
    new TypeReference<List<TestDataYaml>>(){}
    );

    return data;
    }


    @Test
    public void test() {
    System.out.println("yaml" + data.getExpect());
    collector.checkThat(data.getReal() + data.getExpect(), equalTo(Integer.parseInt(data.getStr())));
    }
    }

    package com.zdlh.suite;

    public class TestDataYaml {

    public String getStr() {
    return str;
    }

    public void setStr(String str) {
    this.str = str;
    }

    private String str;

    public int getReal() {
    return real;
    }

    public void setReal(int real) {
    this.real = real;
    }

    private int real;

    public int getExpect() {
    return expect;
    }

    public void setExpect(int expect) {
    this.expect = expect;
    }

    private int expect;
    }

    yaml

    - real: 1
    expect: 2
    str: "3"

    - real: 2
    expect: 2
    str: "3"

    - real: 3
    expect: 2
    str: "4"
  • @BeforeClass
    public void setUp () {
    baseURI = "http://jenkins.testing-studio.com"; //设置默认请求URL
    port = 8081; //设置请求默认端口号
    enableLoggingOfRequestAndResponseIfValidationFails(); //如果验证失败,启用请求和响应日志记录
    //proxy("127.0.0.1",8888); //设置代理
    }

    /**
    * 获取登陆cookies
    * @return
    */

    public Map getJenkinsCookis() {

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("j_username", "ywj");
    map.put("j_password", "123");
    map.put("remember_me",false);
    map.put("from", "/");

    Response response = given().formParams(map)
    .when()
    .post("/j_acegi_security_check")
    .then()
    .statusCode(302).extract().response();
    Map str = response.getCookies();
    System.out.println("cookies: "+str);
    return str;
    }

    /**
    * 运行job
    */

    @Test
    public void runJenkinsJob() {
    final Map cookies = getJenkinsCookis();
    filters(new Filter() {
    @Override
    public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
    requestSpec.cookies(cookies);
    Response response = ctx.next(requestSpec, responseSpec);

    return response;
    }
    }
    );

    given().post("/job/demo/build").then().statusCode(201);

    }

    /**
    * 解析断言
    */

    @Test
    public void test() {
    System.out.println("filters_num: " + filters().size());
    reset(); //因为前面设置了默认请求参数这里清除下
    enableLoggingOfRequestAndResponseIfValidationFails(); //如果验证失败,启用请求和响应日志记录
    filters(new Filter() {
    @Override
    public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
    Response response = ctx.next(requestSpec, responseSpec);
    System.out.println("origin response");
    System.out.println(response.getBody().asString());

    System.out.println("decode response");
    String contentDecode = Base64Str(response.getBody().asString());
    System.out.println(contentDecode);

    Response newResponse = new ResponseBuilder().clone(response)
    .setContentType(ContentType.JSON)
    .setBody(contentDecode)
    .build();
    System.out.println("response filter");
    System.out.println(newResponse.getBody().asString());

    return newResponse;
    }
    });


    given()
    .auth().basic("hogwarts", "123456")
    .when().get("http://jenkins.testing-studio.com:9001/base64base64.json")
    .then().statusCode(200)
    .body("data.items[0].size()",equalTo(3))
    .body("data.items[0].market.status",equalTo("休市"))
    .body("data.items[0].quote.exchange",equalTo("SH"))
    .body("data.items[0].quote.current.toDouble()", is(2681.64))
    .body("data.items.quote.find { it.symbol == 'SH000001'}.current.toDouble()",closeTo(2681.64,10))
    ;
    }

    /**
    * 解析Base64编码
    * @param responseStr
    * @return
    */

    public String Base64Str(String responseStr) {
    String str = null;
    if (responseStr != null) {
    str = new String(Base64.decodeBase64(responseStr));
    if (!str.contains("{")) {
    str = new String(Base64.decodeBase64(str));
    }
    }

    return str;
    }
  • @Test
    public void header() {
    useRelaxedHTTPSValidation();

    Response response = given()
    .config(RestAssuredConfig.config().
    jsonConfig(JsonConfig.jsonConfig().
    numberReturnType(JsonPathConfig.NumberReturnType.DOUBLE)))
    .log().all()
    .header("Content-Type","application/json;charset=UTF-8")
    .cookie("xq_a_token","9c75d6bfbd0112c72b385fd95305e36563da53fb")
    .queryParam("symbol","SOGO")
    .when()
    .get("https://stock.xueqiu.com/v5/stock/quote.json");

    response.then()
    .log().all()
    .statusCode(200)
    //标记
    .body("data.quote.symbol",equalTo("SOGO"))
    //名称
    .body("data.quote.name", equalTo("搜狗"))
    //币种
    .body("data.quote.currency", equalTo("USD"))
    //价格
    .body("data.quote.current", is(7.55))
    .body("data.quote.current", closeTo(7.55, 0.3))

    ;

    }
  • 真机启动 WebDriverAgent报错

    [debug] [XCUITest] iproxy exited with code 'null'
    [debug] [XCUITest] Removing WDA application from device
    [XCUITest] Error: Unable to launch WebDriverAgent because of xcodebuild failure: "xcodebuild failed with code 65". Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.


    .setCapability("xcodeOrgId", "GG7ZFT8T49")

    ###已解决 参考地址https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md
    node安装appium下的webdriveragent 用xcode重新配置开发者证书 配置成自己的

  • @seveniruby 代码里有哈

  • ###用appium测试H5 碰到这样一个问题
    定位到一个元素,然后执行点击操作,页面已经点击成功跳转了页面,appium没收到点击返回结果等了2分钟后又做了一次点击操作这时页面已经跳转了没有这个元素了所以报错: stale element reference: element is not attached to the page document
    求解为什么在第一次点击后appium没收到点击事件返回的结果?
    (Session info: chrome=68.0.3440.91)
    (Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.13.6 x86_64)
    appium=1.8.1

    以下log

    public void run() throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android"); //手机os
    capabilities.setCapability("platformVersion", "7.0"); //真机的Android版本
    capabilities.setCapability("deviceName", "5LM0215C25003252"); //adb得到设备信息
    //capabilities.setCapability("udid", "0915f90d16d31004");
    capabilities.setCapability("browserName", "chrome");
    // capabilities.setCapability("unicodeKeyboard", true); //使用unicodeKeyboard的编码方式来发送字符串
    // capabilities.setCapability("resetKeyboard", true);
    System.out.println(capabilities);
    browserdriver = new AndroidDriver<WebElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);


    browserdriver.get("http://m.58.com/bj/shenghuo.shtml?58hm=m_home_shenghuo_new&58cid=1&from=home_shenghuo&PGTID=0d100000-0000-1d11-3826-90c683b2b063&ClickID=3");


    browserdriver.navigate().refresh();
    for(Object c : browserdriver.getContextHandles()){
    System.out.println(c.toString());
    }

    //browserdriver.context("CHROMIUM");
    //System.out.println(browserdriver.getPageSource());
    browserdriver.findElement(By.xpath("(//*[@class='columns']/dd/div/a)[1]"));
    browserdriver.findElement(By.xpath("(//*[@class='columns']/dd/div/a)[1]")).click();
    browserdriver.navigate().back();
    browserdriver.navigate().forward();
    System.out.println(browserdriver.getPageSource());
    System.out.println("已跳转");
    Utils.sleep(5);
    browserdriver.navigate().refresh();
    for(Object c : browserdriver.getContextHandles()){
    System.out.println(c.toString());
    }
    System.out.println("开始打电话");
    List<WebElement> call_list = (List<WebElement>) browserdriver.findElements(By.xpath("//div[@class=\"item-icon tel_ico_cn_s\" and @username='搬家热线']"));
    call_list.get(0).click();

    }
  • 8.14 为了联盟 at August 13, 2018

    4个字勾起多少往事。。。
    为了联盟!!!
    干翻部落🐽