Esempio n. 1
0
        private void Tap(int xOffset, int yOffset)
        {
            System.Threading.Thread.Sleep(100);
            //the screenshot can take the place of sleeping instead

            Console.WriteLine("Tap start");
            PointerInputDevice touch         = new PointerInputDevice(PointerKind.Touch);
            ActionSequence     touchSequence = new ActionSequence(touch, 0);

            touchSequence.AddAction(touch.CreatePointerMove(CoordinateOrigin.Pointer, xOffset, yOffset, TimeSpan.Zero));
            touchSequence.AddAction(touch.CreatePointerDown(PointerButton.TouchContact));
            touchSequence.AddAction(touch.CreatePointerUp(PointerButton.TouchContact));
            List <ActionSequence> actions = new List <ActionSequence> {
                touchSequence
            };

            session.PerformActions(actions);

            if (record)
            {
                String eventFolder = installDirectory + "\\" + currentEventName;
                String filename    = eventFolder + "\\" + currentEventName + "_" + currentEventTapCount + ".png";
                currentEventTapCount++;
                Bitmap bmp = imageComparer.ScreenshotLockBits(width, height);
                bmp.Save(filename, ImageFormat.Png);
                bmp.Dispose();//doesn't work?
            }

            Console.WriteLine("Echo: " + actions[actions.Count - 1].ToString());
            Console.WriteLine("Tap end");
        }
Esempio n. 2
0
        public void RepeatTaps(List <Coordinate> list, String filename)
        {
            Console.WriteLine("RepeatTaps()");
            //Point point;
            int x;
            int y;
            int timeDiff;

            for (int i = 0; i < list.Count; i++)
            {
                x = list[i].getX();
                y = list[i].getY();
                Tap(x, y);

                //from filename, save current
                String eventFolder      = installDirectory + "\\" + GetFilename(filename);
                String currentFileName  = eventFolder + "\\" + GetFilename(filename) + "_" + i + "_current.png";
                String baselineFileName = eventFolder + "\\" + GetFilename(filename) + "_" + i + ".png";
                String diffFileName     = eventFolder + "\\" + GetFilename(filename) + "_" + i + "_diff.png";

                Bitmap bmp = imageComparer.ScreenshotLockBits(width, height);
                bmp.Save(currentFileName, ImageFormat.Png);

                //from filename, get baseline
                Snapshot expected = Snapshot.FromFile(baselineFileName);
                imageComparer.CompareImages(expected, Snapshot.FromBitmap(bmp), diffFileName);

                //Now taken cared off in the JsonSimpleWrapper
                ////take into consideration the end of the list
                //if (i == (list.Count - 1))
                //{
                //    timeDiff = 0;
                //    list[i].setTimeDiff(timeDiff);
                //}
                //else
                //{
                //    //take into consideration the time between the next step and the current one.
                //    //Wait for that amount of time
                //    Console.WriteLine(list[i + 1].getTimestamp() + " - " + list[i].getTimestamp() + " = " + (list[i + 1].getTimestamp() - list[i].getTimestamp()));
                //    timeDiff = list[i + 1].getTimestamp() - list[i].getTimestamp();
                //    if (timeDiff < 0)
                //    {
                //        Console.WriteLine("timeDiff is less than 0");
                //        timeDiff = 0;
                //    }
                //    list[i].setTimeDiff(timeDiff);
                //    Console.WriteLine("Waiting for : " + timeDiff + " ms");
                //    System.Threading.Thread.Sleep(timeDiff);
                //}

                System.Threading.Thread.Sleep((int)list[i].getTimeDiff());
            }
        }