• 课后作业

    package org.openqa.selenium.chrome;

    import org.junit.Test;
    import org.mockito.Mockito;

    import static org.hamcrest.CoreMatchers.equalTo;
    import static org.junit.Assert.assertThat;

    public class ChromeDriverInfoTest {

    private ChromeDriverInfo driverInfo = new ChromeDriverInfo();

    @Test
    public void getDisplayName() {
    String name = driverInfo.getDisplayName();
    assertThat(name, equalTo("Chrome"));
    }

    @Test
    public void isSupporting() {
    ChromeOptions mockCap = Mockito.mock(ChromeOptions.class);
    //TODO
    //2.23之后的mockito会报错: Mockito can only mock non-private & non-final classes.
    //将mockito设定为 2.23.0,可正常运行. 原因未知.
    Mockito.when(mockCap.getBrowserName()).thenReturn("");
    Mockito.when(mockCap.getCapability(Mockito.anyString())).thenReturn(null);
    assertThat(driverInfo.isSupporting(mockCap), equalTo(false));


    Mockito.when(mockCap.getBrowserName()).thenReturn("chrome");
    assertThat(driverInfo.isSupporting(mockCap), equalTo(true));

    Mockito.when(mockCap.getBrowserName()).thenReturn("");
    Mockito.when(mockCap.getCapability("chromeOptions")).thenReturn("");
    assertThat(driverInfo.isSupporting(mockCap), equalTo(true));

    Mockito.when(mockCap.getCapability(Mockito.anyString())).thenReturn(null);
    Mockito.when(mockCap.getCapability("goog:chromeOptions")).thenReturn("");
    assertThat(driverInfo.isSupporting(mockCap), equalTo(true));
    }

    }

  • http://47.95.238.18:10080/ricky/homework/-/network/master

    1) init master/release/develop

    git init
    git add .
    git commit -m "init"
    git push

    # release
    git checkout -b release
    git push -u origin release
    # set protection on gitlab

    # develop
    git checkout -b develop
    # edit
    git commit -a -m "dev1"
    # edit
    git commit -a -m "dev2"
    # push
    git push -u origin develop

    # mr develop to release on gitlab
    # mr release to master on gitlab
    # tag 1.0

    2) feature 1

    git checkout develop
    git checkout -b feature_login_20190921
    # edit
    git commit -a -m "f_login_1"
    # edit
    git commit -a -m "f_login_2"
    # merge dev to feature
    git merge develop
    # fix conflicts
    git commit -a -m "merge dev to feature; fix conflicts"
    git push -u feature_login_20190921

    3) release 2

    git checkout develop
    # merge feature_login to develop (conflicts have been fixed on step2)
    git merge feature_login_20190921
    git push develop

    # mr develop to release on gitlab

    4) more features

    git checkout develop
    git checkout -b feature_order_20190921

  • 作业1

    p=20444
    top -b -p $p -n 20 -d 1 | grep --line-buffered -E "^ +$p" \
    | awk 'BEGIN{print("cpu","mem")}\
    { print $9,$10;cpu+=$9;mem+=$10 }\
    END{ print("---");if(NR>0){print(cpu/NR,mem/NR)} }'

    课后作业

    page_source(){
    adb shell "uiautomator dump --compressed && cat /sdcard/window_dump.xml"
    }

    inspect(){
    page_source \
    | sed -E 's#>#>\n#g' \
    | awk -F "\"" -v indent=0 \
    '{\
    offset=0;\
    if ($1~/^ *<node /) {\
    if ($1~/NAF=$/) {\
    offset=2;\
    }\
    text=$(offset+4);\
    r_id=$(offset+6);\
    bounds=$(offset+34);\
    if (text!~/^$/||r_id!~/^$/) {\
    for (i=0;i<indent;i++){\
    printf("--");\
    }\
    text=substr(text,1,10);\
    location_len=index(bounds,"][");\
    location=substr(bounds,1,location_len);\
    printf(" resource-id=\"%s\" text=\"%s\" location=\"%s\"\n",r_id,text,location);\
    }\
    \
    if ($0~/[^\/]> *$/) {\
    indent+=1;\
    }\
    } else if ($1~/^ *<\/node>/) {\
    indent-=1;\
    }\
    }'
    }

    说明:

    1. dump
    2. 用sed拆分行(从>后面拆分)
    3. awk: 用引号作为分隔符(因为text和content-desc中可能有空格,不好处理)
    4. awk: 遇到有NAF的行,需要对指针做个偏移
    5. awk: 遇到标签未闭合的行$0~/[^\/]> *$/,说明下一个节点是子节点,需要增加一个缩进
    6. awk: 遇到</node>, 说明下一个节点辈分+1,需要恢复一个缩进
    7. awk: 遇到符合条件的节点text !~ /^$/ || r_id !~ /^$/,输出id/text/location

    注意:
    text或content-desc中有可能出现text= resource-id= bounds=等字符串;不可能出现" < >等字符。

  • AWK 学习笔记和心得 at September 10, 2019

    👍 很有参考价值,感谢

  • 作业1.

    awk '$9==404 {print $0}' 1206.log | wc -l

    结果:10549

    作业3.

    awk '{print $1}' 1206.log | sort | uniq -c | sort -nr | head -n 3

    结果:

    10931 216.244.66.241
    4370 115.236.50.18
    2203 127.0.0.1

    作业4.

    方法1.

    awk '$7~/^\/topics\/[0-9]+($|\?|(\/replies\/))/{print $7}' 1206.log | \
    sed 's#?.*##' | \
    sed -E 's#/replies/.*#/replies#g' | \
    sed -E 's#/[0-9]+##g' | \
    sort | uniq -c

    结果:
    12163 /topics
    9758 /topics/replies

    说明:

    1. 将url提取出来,顺便过滤,只保留/topics/1234 /topocs/1234?xxx /topocs/1234/replies/xxxx 这三种格式的url
    2. 将问号后的内容全删除,剩下 /topics/1234 /topocs/1234/replies/xxxx 这两种格式的url
    3. 将replies后的内容全删除,剩下/topics/1234 /topocs/1234/replies 这两种格式的url
    4. 将数字删除,剩下/topics /topocs/replies

    方法2.

    # /topics/xxx
    # /topics/xxx?xxxxx
    awk '$7 ~ /\/topics\/[0-9]+($|\?)/ {print $7}' 1206.log | wc -l

    # /topics/xxx/replies/xxxx
    awk '$7 ~ /\/topics\/[0-9]+\/replies\// {print $7}' 1206.log | wc -l

    结果:
    12163
    9758

  • 有些popup window需要点击空白处关闭,如果Focusable设为true,就不能实现这个需求了