Пример #1
0
        private void GetAllGoodsInCategory(NcpAppElement category3Element)
        {
            try
            {
                hasNoneNewElementTime = 0;
                GoodsElementList      = new NcpAppElementList();
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.SwipeDisplayElements(new Point(300, 1000),
                                               new Point(300, 300),
                                               1000,
                                               4000,
                                               GetCategoryGoodsItems);

                //保存到文件
                string[] goodsColumns = new string[] { "name",
                                                       "price",
                                                       "unit",
                                                       "category1Name",
                                                       "category2Name",
                                                       "category3Name" };
                Dictionary <string, int> goodsColumnDic = CommonUtil.InitStringIndexDic(goodsColumns);
                string      goodsFilePath = GetCategoryGoodsFilePath(category3Element.Id);
                ExcelWriter goodsEW       = new ExcelWriter(goodsFilePath, "List", goodsColumnDic, null);

                string category1Name = category3Element.Attributes["category1Name"];
                string category2Name = category3Element.Attributes["category2Name"];
                string category3Name = category3Element.Name;

                for (int i = 0; i < GoodsElementList.Count; i++)
                {
                    NcpAppElement element           = GoodsElementList[i];
                    string        name              = element.Name;
                    string        price             = element.Attributes["price"];
                    string        unit              = element.Attributes["unit"];
                    Dictionary <string, string> row = new Dictionary <string, string>();
                    row.Add("name", name);
                    row.Add("price", price);
                    row.Add("unit", unit);
                    row.Add("category1Name", category1Name);
                    row.Add("category2Name", category2Name);
                    row.Add("category3Name", category3Name);
                    goodsEW.AddRow(row);
                }
                goodsEW.SaveToDisk();
            }
            catch (Exception ex)
            {
                throw new Exception("获取商品信息失败, categoryId = " + category3Element.Id, ex);
            }
        }
Пример #2
0
        private NcpAppElementList GetCategory1Items()
        {
            NcpAppElementList allC1Elements = new NcpAppElementList();
            //ReadOnlyCollection<AndroidElement> allC1Nodes = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.TextView[1]", true);
            ReadOnlyCollection <AndroidElement> allC1Nodes = AppAccess.GetElementsByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView[1]", true);

            foreach (AppiumWebElement c1Node in allC1Nodes)
            {
                NcpAppElement c1Element = new NcpAppElement();
                c1Element.Name = c1Node.Text;
                c1Element.Id   = c1Element.Name;
                allC1Elements.Add(c1Element);
            }
            return(allC1Elements);
        }
Пример #3
0
        private void GetAllGoodsInCategory(string locationName, NcpAppElement categoryElement)
        {
            try
            {
                hasNoneNewElementTime = 0;
                GoodsElementList      = new NcpAppElementList();
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.SwipeDisplayElements(new Point(winSize.Width - 20, winSize.Height - 200),
                                               new Point(winSize.Width - 20, 400),
                                               1000,
                                               10000,
                                               GetCategoryGoodsItems);

                //保存到文件
                int      goodsCount   = int.Parse(categoryElement.Attributes["count"]);
                string[] goodsColumns = new string[] { "id",
                                                       "name",
                                                       "price",
                                                       "categoryName",
                                                       "locationName" };
                Dictionary <string, int> goodsColumnDic = CommonUtil.InitStringIndexDic(goodsColumns);
                string      goodsFilePath = (goodsCount == GoodsElementList.Count ? this.GetCategoryGoodsFilePath(locationName, categoryElement.Id) : this.GetCategoryGoodsFilePath("_Error_" + locationName, categoryElement.Id));
                ExcelWriter goodsEW       = new ExcelWriter(goodsFilePath, "List", goodsColumnDic, null);

                for (int i = 0; i < GoodsElementList.Count; i++)
                {
                    NcpAppElement element           = GoodsElementList[i];
                    string        id                = element.Id;
                    string        name              = element.Name;
                    string        price             = element.Attributes["price"];
                    Dictionary <string, string> row = new Dictionary <string, string>();
                    row.Add("id", element.Id);
                    row.Add("name", name);
                    row.Add("categoryName", categoryElement.Name);
                    row.Add("price", price);
                    row.Add("locationName", locationName);
                    goodsEW.AddRow(row);
                }
                goodsEW.SaveToDisk();
            }
            catch (Exception ex)
            {
                throw new Exception("获取商品信息失败, locationName = " + locationName + ", categoryId = " + categoryElement.Id, ex);
            }
        }
Пример #4
0
        private void GetCategoryInfo(string locationName)
        {
            try
            {
                AndroidElement categoryMenuElement = AppAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "分类" }, true, true, true);
                categoryMenuElement.Click();

                CategoryElementList = new NcpAppElementList();
                Size winSize = AppAccess.GetWindowSize();
                AppAccess.SwipeDisplayElements(new Point(winSize.Width - 20, winSize.Height - 20),
                                               new Point(winSize.Width - 20, 200),
                                               2000,
                                               5000,
                                               GetCategoryItems);
                NcpAppElementList sortedCategoryElements = CategoryElementList.SortByPosition();

                //分级处理
                List <NcpAppElement> level1Elements    = new List <NcpAppElement>();
                NcpAppElement        lastLevel1Element = null;
                for (int i = 1; i < sortedCategoryElements.Count; i++)
                {
                    NcpAppElement element = sortedCategoryElements[i];
                    if (element.TypeName == "Level1")
                    {
                        level1Elements.Add(element);
                        lastLevel1Element = element;
                    }
                    else
                    {
                        lastLevel1Element.Children.Add(element);
                    }
                }

                //保存到文件

                string[] categoryColumns = new string[] { "id",
                                                          "category1Name",
                                                          "category2Name",
                                                          "needGrab",
                                                          "goodsCount",
                                                          "locationName" };
                Dictionary <string, int> categoryColumnDic = CommonUtil.InitStringIndexDic(categoryColumns);
                string      categoryFilePath = this.GetCategoryFilePath(locationName);
                ExcelWriter categoryEW       = new ExcelWriter(categoryFilePath, "List", categoryColumnDic, null);

                for (int i = 0; i < level1Elements.Count; i++)
                {
                    NcpAppElement element           = level1Elements[i];
                    string        category1Name     = element.Name;
                    string        needGrab          = element.Children.Count == 0 ? "是" : "否";
                    string        goodsCount        = element.Attributes["count"];
                    Dictionary <string, string> row = new Dictionary <string, string>();
                    row.Add("id", element.Id);
                    row.Add("category1Name", category1Name);
                    row.Add("category2Name", "");
                    row.Add("needGrab", needGrab);
                    row.Add("goodsCount", goodsCount);
                    row.Add("locationName", locationName);
                    categoryEW.AddRow(row);
                    if (element.Children.Count > 0)
                    {
                        for (int j = 0; j < element.Children.Count; j++)
                        {
                            NcpAppElement childElement           = element.Children[j];
                            string        category2Name          = childElement.Name;
                            string        childGoodsCount        = childElement.Attributes["count"];
                            Dictionary <string, string> childRow = new Dictionary <string, string>();
                            childRow.Add("id", childElement.Id);
                            childRow.Add("category1Name", category1Name);
                            childRow.Add("category2Name", category2Name);
                            childRow.Add("needGrab", "是");
                            childRow.Add("goodsCount", childGoodsCount);
                            childRow.Add("locationName", locationName);
                            categoryEW.AddRow(childRow);
                        }
                    }
                }
                categoryEW.SaveToDisk();
            }
            catch (Exception ex)
            {
                throw new Exception("获取分类信息失败.", ex);
            }
        }
Пример #5
0
        private void GetCategoryInfo()
        {
            string categoryFilePath = this.GetCategoryFilePath();

            if (!File.Exists(categoryFilePath))
            {
                try
                {
                    //获取一级分类信息
                    NcpAppElementList allC1Elements = this.GetCategory1Items();

                    foreach (NcpAppElement c1Element in allC1Elements)
                    {
                        //AndroidElement c1Node = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.TextView[1]", new string[] { c1Element.Name }, true);
                        AndroidElement c1Node = AppAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.ListView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView[1]", new string[] { c1Element.Name }, true);
                        c1Node.Click();

                        CategoryElementList = new NcpAppElementList();
                        Size winSize = AppAccess.GetWindowSize();
                        AppAccess.SwipeDisplayElements(new Point(300, 1000),
                                                       new Point(300, 300),
                                                       2000,
                                                       2000,
                                                       GetSubCategoryItems);

                        //分级处理
                        List <NcpAppElement> level2Elements    = new List <NcpAppElement>();
                        NcpAppElement        lastLevel2Element = null;
                        for (int i = 0; i < CategoryElementList.Count; i++)
                        {
                            NcpAppElement element = CategoryElementList[i];
                            if (element.TypeName == "Level2")
                            {
                                level2Elements.Add(element);
                                lastLevel2Element = element;
                            }
                            else
                            {
                                lastLevel2Element.Children.Add(element);
                            }
                        }
                        c1Element.Children.AddRange(level2Elements);
                    }



                    //保存到文件

                    string[] categoryColumns = new string[] { "category1Name",
                                                              "category2Name",
                                                              "category3Name" };
                    Dictionary <string, int> categoryColumnDic = CommonUtil.InitStringIndexDic(categoryColumns);
                    ExcelWriter categoryEW = new ExcelWriter(categoryFilePath, "List", categoryColumnDic, null);

                    for (int i = 0; i < allC1Elements.Count; i++)
                    {
                        NcpAppElement c1Element     = allC1Elements[i];
                        string        category1Name = c1Element.Name;
                        if (c1Element.Children.Count > 0)
                        {
                            for (int j = 0; j < c1Element.Children.Count; j++)
                            {
                                NcpAppElement c2Element     = c1Element.Children[j];
                                string        category2Name = c2Element.Name;
                                if (c2Element.Children.Count > 0)
                                {
                                    for (int k = 0; k < c2Element.Children.Count; k++)
                                    {
                                        NcpAppElement c3Element     = c2Element.Children[k];
                                        string        category3Name = c3Element.Name;

                                        Dictionary <string, string> row = new Dictionary <string, string>();
                                        row.Add("category1Name", category1Name);
                                        row.Add("category2Name", category2Name);
                                        row.Add("category3Name", category3Name);
                                        categoryEW.AddRow(row);
                                    }
                                }
                            }
                        }
                    }
                    categoryEW.SaveToDisk();
                }
                catch (Exception ex)
                {
                    throw new Exception("获取分类信息失败.", ex);
                }
            }
        }