• robotium测试妈妈圈的简单代码


    robotium测试妈妈圈的简单用例代码

    package cn.mama.activity.test;

    import java.util.Iterator;

    import org.junit.Test;

    import com.jayway.android.robotium.solo.By;
    import com.jayway.android.robotium.solo.Solo;
    import com.jayway.android.robotium.solo.WebElement;

    import android.app.Activity;
    import android.test.ActivityInstrumentationTestCase2;
    import android.test.suitebuilder.annotation.SmallTest;
    import android.util.Log;
    import android.view.View;
    import android.widget.EditText;

    @SuppressWarnings("rawtypes")
    public class TestMMQ extends ActivityInstrumentationTestCase2 {//只有apk包,不传参数:被测类

    private Solo solo;
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "cn.mama.activity.Is******ed";//第一个启动的activity,只需要一个就够了,后面的activity不需要也能跑

    private static Class launcherActivityClass;
    static{
    try {
    launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);//装载第一个启动的activity类
    } catch (ClassNotFoundException e) {
    throw new RuntimeException(e);
    }
    }

    @SuppressWarnings("unchecked")
    public TestMMQ() throws ClassNotFoundException {//构造函数,传第一个启动的activity类给父类ActivityInstrumentationTestCase2
    super(launcherActivityClass);
    }



    @Override
    protected void setUp() throws Exception {
    solo = new Solo(getInstrumentation(), getActivity());//启动Instrumentation,获取activity
    }


    @SmallTest
    public void testIsFirstUsed(){
    // solo = new Solo(getInstrumentation(), getActivity());
    solo.assertCurrentActivity("闪屏没有出现", "Is*****sed");
    //solo.clickOnScreen(200, 500);
    //solo.assertCurrentActivity("闪屏没有出现", "Guide");
    solo.clickOnScreen(200, 500);
    for(int i=1;i<5;i++){
    try{
    Thread.sleep(2000);

    solo.scrollToSide(Solo.RIGHT,0.7f);//左滑4次,Solo.RIGHT是不是很坑爹?是的,哥也纠结过
    }catch(Exception e){
    e.getMessage();
    }

    }

    //进入登陆方式选择页
    View view=solo.getView("ll_******ma");//获取妈网账号登录按钮的View
    solo.clickOnView(view);//点击直接账号登录

    /*for(WebElement webElement : solo.getCurrentWebElements()){
    System.out.println("下一个对象是:");
    Log.d("Robotium", "id: '" + webElement.getId() + "' text: '" + webElement.getText() + "' name: '" + webElement.getName() + "' class name: '" + webElement.getClassName() + "' tag name: '" + webElement.getTagName() + "'");
    }*/

    //登录页,输入用户名和密码登录
    EditText et_username=solo.getEditText(0);
    EditText et_password=solo.getEditText(1);
    solo.typeText(et_username, "mama177888");
    solo.typeText(et_password, "11**1");
    View btn_login=solo.getView("********login");//
    solo.clickOnView(btn_login);//
    try{
    Thread.sleep(3000);

    }catch(Exception e){
    e.getMessage();
    }

    //进入首页,点击中间的发帖按钮
    View write_img=solo.getView("write***");//获取妈网账号登录按钮的View
    solo.clickOnView(write_img);

    View sure_img=solo.getView("su****_img");//获取妈网账号登录按钮的View
    solo.clickOnView(sure_img);

    EditText et_write_title=solo.getEditText(0);
    solo.enterText(et_write_title, "帖子标题");
    System.out.println("已输入标题"+et_write_title);

    EditText et_write_content=solo.getEditText(1);
    solo.enterText(et_write_content, "1帖子内容11111");

    View iv_write=solo.getView("iv*****te");//获取妈网账号登录按钮的View
    solo.clickOnView(iv_write);
    try{
    Thread.sleep(3000);

    }catch(Exception e){
    e.getMessage();
    }


    }

    @Override
    public void tearDown() throws Exception {
    solo.finishOpenedActivities();

    }


    }

  • 相关阅读:
    Golang内存管理和垃圾回收
    深入浅出依赖注入及其在抖音直播中的应用
    applications of DFS and BFS
    操作系统上的程序 (什么是程序和编译器)
    安全通告 | 疑似PurpleFox多手段持续实施攻击活动
    日志导致线程Block的这些坑
    聊聊分布式锁
    汇编_action
    操作系统:设计与实现 (2022 春季学期)
    tldr man 查手册效率工具
  • 原文地址:https://www.cnblogs.com/zhitang2009/p/3425058.html
Copyright © 2020-2023  润新知