• 补交作业

    Github: https://github.com/kenny945/XiuqiuDemoTest

    StockItemPage

    package page;

    import org.openqa.selenium.By;

    public class StockItemPage extends BasePage {

    String message;

    public void addSelect(){
    find(By.xpath("//*/android.widget.TextView[@text='加自选']")).click();
    message = find(By.xpath("//*[@class='android.widget.Toast']")).getText();
    }

    public void disSelect(){

    find(By.xpath("//*/android.widget.TextView[@text='设自选']")).click();
    find(text("删除自选")).click();
    message = find(locate("//*[@class='android.widget.Toast']")).getText();
    }


    public String getMessage(){

    return message;
    }

    public SearchPage backtoSearch(){
    find(By.id("action_back")).click();
    return new SearchPage();
    }
    }

    OptionalPage

    package page;

    import driver.Driver;
    import io.appium.java_client.TouchAction;
    import io.appium.java_client.touch.LongPressOptions;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;

    import java.time.Duration;
    import java.util.ArrayList;
    import java.util.List;

    import static io.appium.java_client.touch.offset.ElementOption.element;

    public class OptionalPage extends BasePage{

    String message = "";
    By search = By.id("action_create_cube");
    By searchText = By.id("search_input_text");
    By delAction = By.id("md_title");

    public SearchPage clickCenter(){
    find(By.id("image")).click();
    return new SearchPage();
    }

    public SearchPage search(String key)
    {
    find(search).click();
    find(searchText).sendKeys(key);
    return new SearchPage();

    }
    public ArrayList<String> getAllStockName(){

    ArrayList<String> arrayList = new ArrayList<String>();
    List<WebElement> stocks = Driver.getCurrDriver().findElements(By.id("stockName"));
    if (!((List) stocks).isEmpty()){
    for(WebElement e: stocks){
    arrayList.add(e.getText());
    }
    return arrayList;
    }
    else {
    arrayList.add("Null");
    return arrayList;
    }
    }

    public void delByPress(String content){
    WebElement Elememt = find(text(content));//find(By.xpath("//*[@class='android.widget.TextView']"));
    //TouchActions

    TouchAction action = new TouchAction(Driver.getCurrDriver());
    action.longPress(new LongPressOptions().withElement(element(Elememt)).withDuration(Duration.ofSeconds(2)));
    action.perform();

    find(text("删除")).click();
    message = find(By.xpath("//*[@class='android.widget.Toast']")).getText();
    }

    public SearchPage gotoSearch(){
    find(locate("action_create_cube")).click();
    return new SearchPage();
    }

    public HotStockPage gotohotShare(){
    find(By.id("tv_check")).click(); //"去看看热门股票"
    return new HotStockPage();
    }

    public List<WebElement> getAllSelectStock(){
    List<WebElement> webElements = finds(By.id("portfolio_whole_item"));
    return webElements;
    }

    public String getMessage(){
    return message;
    }
    }

    SearchPage

    package page;

    import driver.Driver;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import sun.awt.windows.WEmbeddedFrame;


    import java.util.ArrayList;
    import java.util.List;

    public class SearchPage extends BasePage {

    By searchText = locate("search_input_text");
    By StockName = locate("stockName");
    By addselect = locate("follow_btn");
    By hasselect = locate("followed_btn");
    By cancel = locate("action_close");

    public SearchPage search(String key)
    {

    find(searchText).sendKeys(key);
    return this;

    }

    public MainPage cancel()
    {
    find(cancel).click();
    return new MainPage();
    }

    public ArrayList<String> getAllStockName(){

    ArrayList<String> arrayList = new ArrayList<String>();
    List<WebElement> stocks = finds(StockName); //Driver.getCurrDriver().findElements(By.id("stockName"));
    if (!((List) stocks).isEmpty()){
    for(WebElement e: stocks){
    arrayList.add(e.getText());
    }
    return arrayList;
    }
    else {
    arrayList.add("Null");
    return arrayList;
    }
    }



    public SearchPage getByStock(){
    return this;
    }

    public ArrayList<String> addSelected(){
    ArrayList<String> arrayList = new ArrayList<String>();

    WebElement select = find(By.xpath("//*[contains(@resource-id,'follow') and contains(@resource-id,'_btn')]"));

    arrayList.add(select.getText());
    select.click();

    return arrayList;
    }

    public SearchPage removeSelected(){
    return this;
    }

    public StockItemPage gotoItem(String content){

    find(text(content)).click();
    return new StockItemPage();
    }

    }

    SearchTest

    import driver.Driver;
    import org.junit.jupiter.api.AfterAll;
    import org.junit.jupiter.api.BeforeAll;
    import org.junit.jupiter.params.ParameterizedTest;
    import org.junit.jupiter.params.provider.CsvSource;
    import page.MainPage;
    import page.SearchPage;

    import static org.hamcrest.CoreMatchers.equalTo;
    import static org.hamcrest.MatcherAssert.assertThat;

    public class SearchTest {

    static MainPage mainPage;
    static SearchPage searchPage;

    @BeforeAll
    static void BeforeAll() {
    mainPage = MainPage.start();
    //searchPage = mainPage.gotoSearch();
    searchPage = mainPage.gotoSearch2();
    }

    @ParameterizedTest
    @CsvSource({
    "pdd, 拼多多",
    "xiaomi, 小米集团-W",
    "法轮功,Null",
    "700,腾讯控股"

    })
    public void search(String key, String expected) {

    String index = searchPage.search(key).getAllStockName().get(0);
    assertThat(index, equalTo(expected));

    }


    @AfterAll
    static void AfterAll(){
    Driver.stop();
    }

    }

    OptionalTest

    import driver.Driver;
    import org.junit.jupiter.api.AfterAll;
    import org.junit.jupiter.api.BeforeAll;
    import org.junit.jupiter.params.ParameterizedTest;
    import org.junit.jupiter.params.provider.CsvSource;
    import page.*;

    import static org.hamcrest.CoreMatchers.equalTo;
    import static org.hamcrest.MatcherAssert.assertThat;

    public class OptionalTest {

    static MainPage mainPage;
    static OptionalPage optionalPage;
    static SearchPage searchPage;
    static HotStockPage hotStockPage;

    @BeforeAll
    static void BeforeAll(){
    mainPage = MainPage.start();
    optionalPage = mainPage.gotoOption();

    }

    @ParameterizedTest
    @CsvSource({
    "pdd, 拼多多",
    "xiaomi, 小米集团-W",
    "700,腾讯控股",
    //"法轮功,Null",

    })
    public void search(String key, String expected){
    String expectedMsg="添加成功";
    searchPage = optionalPage.gotoSearch();
    searchPage.search(key);
    String index = searchPage.getAllStockName().get(0);
    assertThat(index, equalTo(expected));

    StockItemPage stockItemPage = searchPage.gotoItem(index);
    stockItemPage.addSelect();
    String Message = stockItemPage.getMessage();
    stockItemPage.backtoOptional();
    assertThat(Message, equalTo(expectedMsg));

    }


    @ParameterizedTest
    @CsvSource({
    "拼多多",
    "小米集团-W",
    "腾讯控股",
    //"法轮功,Null",

    })
    public void testDelByPress(String key){
    String expectedMsg="已从自选删除";
    optionalPage.delByPress(key);
    String msg = optionalPage.getMessage();
    assertThat(msg, equalTo(expectedMsg));
    }


    @AfterAll
    static void AfterAll(){
    Driver.stop();
    }


    }


  • 你这里每次get_driver ,都会重新webdriver.Remote 一把的话肯定是会重启app的,分开一个start函数来启动好一些

  • 1.

    #1.
    cat /tmp/nginx.log |grep -E "404|500"|head -5
    #2.
    cat /tmp/nginx.log |grep -E "500" -C1

  • 测试代码:


    from xpinyin import Pinyin,PinyinToneMark
    import pytest


    class TestPinyin():
    pinyin = Pinyin()

    #test_data
    data_for_getpinyin = [
    (u"测试", "ce-shi" ),
    (u" ", " "),
    (u"嗯", u"en"),
    (u"爱好", u"ai-hao"),

    ]
    data_for_getpinyin2 = [
    (u"测试", " ", "ce shi" ),
    (u"嗯","-", u"en"),
    (u"αβ", "&", "αβ"),
    (u"测试开发", "*", u"ce*shi*kai*fa"),


    ]
    data_for_getpinyin3 = [
    (u"测试", "-", "", "ce-shi" ),
    (u"ceshi", "-", "upper", "ceshi"),
    (u"爱好","-","marks", u"ài-hào"),
    (u"测试","-", "numbers", "ce4-shi4"),
    (u"测试", "@","marks", u"cè@shì")
    ]

    data_for_getpinyin4 = [
    (u"测试", "-", None, "lower", "ce-shi" ),
    (u"测试", "-", "", "upper", "CE-SHI"),
    (u"CE-SHI", "-", "", "upper", "CE-SHI"),
    (u"测试", "-", "marks", "lower", "cè-shì"),
    (u"测试", "-", "numbers", "capitalize","Ce4-Shi4"),
    (u"测试", "-", "marks", "upper", u"CÈ-SHÌ"),
    (u"测试", "*", "marks", "capitalize", "Cè*Shì"),
    ]
    data_for_get_initials = [
    ("上海", '', "SH"),
    ("上海", '-', "S-H"),
    ("αβ", "&" ,"α&β"),
    (" ", '', " "),
    ("上海ren", '-', "S-H-r-e-n")
    ]
    data_for_get_initial = [
    (u"上" , "S"),
    (u"&", "&",),
    ("α", "α"),
    (u"嗯", u"E"),

    ]


    # for default args:

    def test_get_pinyin_default(self):
    assert self.pinyin.get_pinyin() == "ni-hao"

    def test_get_initial(self):
    assert self.pinyin.get_initial() == "N"

    def test_get_initials(self):
    assert self.pinyin.get_initials() == "N-H"


    @pytest.mark.parametrize("_chars, expected", data_for_getpinyin)
    def test_get_pinyin1(self,_chars, expected):
    assert self.pinyin.get_pinyin(_chars) == expected

    @pytest.mark.parametrize("_chars, _splitter, expected", data_for_getpinyin2)
    def test_get_pinyin2(self,_chars, _splitter, expected):
    assert self.pinyin.get_pinyin(_chars, _splitter) == expected

    @pytest.mark.parametrize("_chars, _splitter, _tone_marks, expected", data_for_getpinyin3)
    def test_get_pinyin3(self,_chars, _splitter, _tone_marks, expected):
    assert self.pinyin.get_pinyin(_chars, _splitter, _tone_marks, ) == expected

    @pytest.mark.parametrize("_chars, _splitter, _tone_marks, _convert, expected", data_for_getpinyin4)
    def test_get_pinyin4(self,_chars, _splitter, _tone_marks, _convert, expected):
    assert self.pinyin.get_pinyin(_chars, _splitter, _tone_marks, _convert) == expected



    @pytest.mark.parametrize("_chars, _splitter, expected", data_for_get_initials)
    def test_get_initials(self,_chars, _splitter, expected):
    assert self.pinyin.get_initials(_chars, _splitter) == expected

    @pytest.mark.parametrize("_chars, expected", data_for_get_initial)
    def test_get_initial(self,_chars, expected):
    assert self.pinyin.get_initial(_chars) == expected

    执行测试:

    pytest --cov=xpinyin --alluredir=result

    测试结果及代码覆盖率:

    allure-report(简单用法):

    allure serve result

    发现bug:

    1.多音字转换有问题

  • 测试代码:

    package TestXunit;

    import DemoXunit.Login;
    import DemoXunit.Shopping;
    import LoginData.BuyData;
    import org.testng.Assert;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;

    public class BuyTest {

    Login login = new Login();
    Shopping shop = new Shopping();

    @BeforeMethod
    public void beforeMethod(){

    System.out.println("--------------");
    }

    @Test(dataProvider = "getBuysData", dataProviderClass = BuyData.class)
    public void testBuys(String user,String pwd, int proId, int count, int except){
    try{
    login.userLogin(user, pwd);
    int buyResult = shop.buys(proId, count);
    Assert.assertEquals(buyResult, except);
    //my log for test
    if(-2 == buyResult ) {
    System.out.println("Session Error,buys fail!");
    }else if(-1 == buyResult){
    System.out.println("product empty,buys fail!");
    }else if(0 == buyResult){
    System.out.println("No more product,buys fail!");
    }else if(1 == buyResult){
    System.out.println("Buy Succ");
    }
    }catch (Exception e){
    System.out.println("illegal Params");
    }
    }

    @AfterMethod
    public void afterMethod(){

    }

    }

    数据驱动:

    package LoginData;
    import org.testng.annotations.DataProvider;

    public class BuyData {

    @DataProvider
    public Object[][] getBuysData(){
    return new Object[][]{
    {"","",1,1,-2}, //非登录状态
    {"Hanmeimei","",1,1,-2}, //非登录状态
    {"admin","",1,1,-2}, //非登录状态
    {"","testpwd",1,1,-2}, //非登录状态
    {"LiLei","testpwd",1,-1,-1},//购买数量非法
    {"LiLei","testpwd",1,1,0}, //库存不足,购买失败
    {"LiLei","testpwd",2,11,0}, //购买数量大于库存
    {"LiLei","testpwd",3,1,1}, //库存正常,购买成功
    {"admin","admin",3,1,0}, //库存不足,购买失败
    {"LiLei","testpwd",4,1,-1}, //非售卖商品
    {"admin","admin",2,10,1}, //库存正常,购买成功
    {"admin","admin",2,1,0}, //库存不足,购买失败

    };
    }
    }

    testng 配置:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="All Test Suite">
    <test verbose="1" preserve-order="true" name="D:\Android\WorkSpace\XunitDemo">
    <groups>
    <dependencies>
    <group name="group" depends-on="">
    <classes>
    <class name="TestXunit.BuyTest">
    <methods>
    <include name="testBuys"></include>
    </methods>
    </class>
    </classes>
    </group>
    </dependencies>
    </groups>
    </test>
    </suite>

    测试结果:

  • 1、提取系统state连接种类

    netstat -tn|sed 1,2d|awk '{print $6}'|sort|uniq

    result:
    ESTABLISHED
    TIME_WAIT

    2、teserhome 某一精华帖任意一回复贴的数量
    任意一个精华帖会有多个回复、找出任意一个回复贴的点赞数

    ids=`curl -s https://testerhome.com|grep "fa fa-diamond" -B1|grep "href"|awk -F '\"' '{print $4}'|grep "/topics.*"|sort|uniq`

    for id in $ids
    do
    url="https://testerhome.com"$id;
    zan=`curl -s $url |grep Reply |awk -F '\"' '{print $4}'|sort -r|head -1`
    if [ "$zan" -eq "0" ]
    then
    echo $id "没有被赞的回复"
    else
    echo $id "回复被点赞最多个数为:"$zan
    fi
    done

    result:
    /topics/16299 回复被点赞最多个数为:1
    /topics/16354 回复被点赞最多个数为:5
    /topics/16376 没有被赞的回复
    /topics/16436 回复被点赞最多个数为:2
    /topics/16498 回复被点赞最多个数为:2
    /topics/16556 回复被点赞最多个数为:12
    /topics/16605 回复被点赞最多个数为:1
    /topics/16689 没有被赞的回复
    /topics/16790 回复被点赞最多个数为:2
    /topics/16909 回复被点赞最多个数为:1
    /topics/16920 没有被赞的回复
    /topics/17004 没有被赞的回复
    /topics/17066 没有被赞的回复
    /topics/17068 回复被点赞最多个数为:4
    /topics/17117 回复被点赞最多个数为:1
    /topics/17179 回复被点赞最多个数为:3
    /topics/17251 回复被点赞最多个数为:3
    /topics/17292 回复被点赞最多个数为:1
  • Author only
  • go哥V5