<commit_before>package sunmi.com.sunmiauto;

import android.app.Instrumentation;
import android.os.Build;
import android.os.Environment;
import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.util.Log;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

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

import javax.mail.MessagingException;


/**
 * Created by Administrator on 2017/6/7.
 */

public class SunmiAppStore {
    static Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    static UiDevice device = UiDevice.getInstance(instrumentation);


    @Before
    //每条测试用例开始前执行操作
    public void setup() throws RemoteException, UiObjectNotFoundException, IOException {
        device.executeShellCommand("am start -n woyou.market/store.ui.activity.HomeActivity");
        SunmiUtil.sleep(2000);
        device.findObject(By.text("推荐")).click();
    }

    @After
    //每条测试用例结束后执行操作
    public void teardown() throws RemoteException {
        SunmiUtil.sleep(1000);
        device.pressHome();
    }

    @BeforeClass
    //该测试类开始前执行操作
    public static void initLiza() throws RemoteException, IOException {
        File dir = new File(Environment.getExternalStorageDirectory() + File.separator + "app_spoon-screenshots");
        Log.v("testDir", Environment.getExternalStorageDirectory() + File.separator + "app_spoon-screenshots");
        class Inner {
            //递归删除文件夹
            private void deleteAll(File file) {
                if(!file.exists()){
                    return;
                }
                if (file.isFile() || file.list().length == 0) {
                    file.delete();
                } else {
                    File[] files = file.listFiles();
                    for (File f : files) {
                        deleteAll(f);//递归删除每一个文件
                        f.delete();//删除该文件夹
                    }
                }
            }
        }
        new Inner().deleteAll(dir);
        dir.mkdir();
    }

    @AfterClass
    //该测试类结束后执行操作
    public static void clearDown() throws MessagingException, RemoteException {

    }


    //测试能够成功打开应用市场
    @Test
    public void testOpenAppStore() {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),5000);
//        device.waitForIdle(10000);
        SunmiUtil.screenshotCap("afterEnter");
        UiObject2 suggObj = device.findObject(By.res("woyou.market:id/fab_me"));
        Assert.assertNotNull("未找到用户入口，判断打开应用市场失败", suggObj);
    }

    //测试新品应用存在
    @Test
    public void testCheckNewArrive() {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        device.findObject(By.res("woyou.market:id/tv_newest_all").text("全部")).clickAndWait(Until.newWindow(), 10000);
        SunmiUtil.screenshotCap("afterClickNewestAll");
        UiObject2 newestAllObj = device.findObject(By.res("woyou.market:id/list_view"));
        Assert.assertNotNull("不存在", newestAllObj);
    }

    //测试新品应用滑动查看
    @Test
    public void testNewScroll() throws UiObjectNotFoundException {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        UiScrollable newAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/recycler_view_newest"));
        newAllScroll.setAsHorizontalList();
        newAllScroll.scrollToEnd(20, 10);
        newAllScroll.scrollToBeginning(20, 10);
    }

    //测试热门中全部应用查看
    @Test
    public void testCheckHotApps() {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部")).clickAndWait(Until.newWindow(), 10000);
        SunmiUtil.screenshotCap("afterClickHotAll");
        UiObject2 hotAllObj = device.findObject(By.res("woyou.market:id/list_view"));
        Assert.assertNotNull("找不到res为woyou.market:id/list_view的对象", hotAllObj);
    }

    //测试热门应用滑动查看
    @Test
    public void testHotScroll() throws UiObjectNotFoundException {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/linear_hot_view"));
        hotAllScroll.scrollToEnd(20, 10);
        hotAllScroll.scrollToBeginning(20, 10);
    }

    //测试分类信息正确
    @Test
    public void testCheckCategory() throws UiObjectNotFoundException {
//        SunmiUtil.screenshotCap();("beforeEnter");<commit_msg>adjust factor to testNewScroll case and add Assert<commit_after>package sunmi.com.sunmiauto;

import android.app.Instrumentation;
import android.os.Build;
import android.os.Environment;
import android.os.RemoteException;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.Until;
import android.util.Log;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

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

import javax.mail.MessagingException;


/**
 * Created by Administrator on 2017/6/7.
 */

public class SunmiAppStore {
    static Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    static UiDevice device = UiDevice.getInstance(instrumentation);


    @Before
    //每条测试用例开始前执行操作
    public void setup() throws RemoteException, UiObjectNotFoundException, IOException {
        device.executeShellCommand("am start -n woyou.market/store.ui.activity.HomeActivity");
        SunmiUtil.sleep(2000);
        device.findObject(By.text("推荐")).click();
    }

    @After
    //每条测试用例结束后执行操作
    public void teardown() throws RemoteException {
        SunmiUtil.sleep(1000);
        device.pressHome();
    }

    @BeforeClass
    //该测试类开始前执行操作
    public static void initLiza() throws RemoteException, IOException {
        File dir = new File(Environment.getExternalStorageDirectory() + File.separator + "app_spoon-screenshots");
        Log.v("testDir", Environment.getExternalStorageDirectory() + File.separator + "app_spoon-screenshots");
        class Inner {
            //递归删除文件夹
            private void deleteAll(File file) {
                if(!file.exists()){
                    return;
                }
                if (file.isFile() || file.list().length == 0) {
                    file.delete();
                } else {
                    File[] files = file.listFiles();
                    for (File f : files) {
                        deleteAll(f);//递归删除每一个文件
                        f.delete();//删除该文件夹
                    }
                }
            }
        }
        new Inner().deleteAll(dir);
        dir.mkdir();
    }

    @AfterClass
    //该测试类结束后执行操作
    public static void clearDown() throws MessagingException, RemoteException {

    }


    //测试能够成功打开应用市场
    @Test
    public void testOpenAppStore() {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),5000);
//        device.waitForIdle(10000);
        SunmiUtil.screenshotCap("afterEnter");
        UiObject2 suggObj = device.findObject(By.res("woyou.market:id/fab_me"));
        Assert.assertNotNull("未找到用户入口，判断打开应用市场失败", suggObj);
    }

    //测试新品应用存在
    @Test
    public void testCheckNewArrive() {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        device.findObject(By.res("woyou.market:id/tv_newest_all").text("全部")).clickAndWait(Until.newWindow(), 10000);
        SunmiUtil.screenshotCap("afterClickNewestAll");
        UiObject2 newestAllObj = device.findObject(By.res("woyou.market:id/list_view"));
        Assert.assertNotNull("不存在", newestAllObj);
    }

    //测试新品应用滑动查看
    @Test
    public void testNewScroll() throws UiObjectNotFoundException {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        UiScrollable newAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/recycler_view_newest"));
        newAllScroll.setAsHorizontalList();
        newAllScroll.scrollToBeginning(10, 10);
        newAllScroll.scrollToEnd(10, 10);
        newAllScroll.scrollToBeginning(10, 10);
        UiScrollable newAllScroll1 = new UiScrollable(new UiSelector().resourceId("woyou.market:id/recycler_view_newest"));
        Assert.assertNotNull("新品上架模块未能找到",newAllScroll1);
    }

    //测试热门中全部应用查看
    @Test
    public void testCheckHotApps() {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部")).clickAndWait(Until.newWindow(), 10000);
        SunmiUtil.screenshotCap("afterClickHotAll");
        UiObject2 hotAllObj = device.findObject(By.res("woyou.market:id/list_view"));
        Assert.assertNotNull("找不到res为woyou.market:id/list_view的对象", hotAllObj);
    }

    //测试热门应用滑动查看
    @Test
    public void testHotScroll() throws UiObjectNotFoundException {
//        SunmiUtil.screenshotCap();("beforeEnter");
//        device.findObject(By.text("应用市场")).clickAndWait(Until.newWindow(),10000);
        SunmiUtil.screenshotCap("afterEnter");
        UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/linear_hot_view"));
        hotAllScroll.scrollToEnd(20, 10);
        hotAllScroll.scrollToBeginning(20, 10);
    }

    //测试分类信息正确
    @Test
    public void testCheckCategory() throws UiObjectNotFoundException {
//        SunmiUtil.screenshotCap();("beforeEnter");
{'fraction_non_alphanumeric': 0.12548176032983777, 'fraction_numerical': 0.013802993636282155, 'mean_word_length': 3.154132539091586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3139026', 'n_tokens_mistral': 3716, 'n_tokens_neox': 3663, 'n_words': 486}