搜尋此網誌

2014年2月7日

Java + Android + Sikuli + UIAutomator = Test automation

Project page: https://code.google.com/p/sikuli-api/

Eclipse:
  • sikuli-api-1.0.2-standalone.jar
  • slf4j-nop-1.7.5.jar
  • log4j-over-slf4j-1.7.5.jar

Example: (Java project)

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Target;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.sikuli.api.DesktopScreenRegion;
import org.sikuli.api.ImageTarget;
import org.sikuli.api.ScreenRegion;
import org.sikuli.api.visual.Canvas;
import org.sikuli.api.visual.DesktopCanvas;


public class SikuliTest {

    private static BufferedImage bi;
    private static JFrame frame;

    public static void main(String[] args) throws Exception {
        try {           
            Util.execCMD("adb push WiFi_UItest.jar /data/local/tmp");
            Util.execCMD("adb shell uiautomator runtest WiFi_UItest.jar -e CheckId 1 -c s2.wifi.TurnOn -c s2.wifi.CheckResult -s");
            Util.execCMD("adb pull /mnt/sdcard/Pictures/test_TurnOn.png C:\\tmp");
           
            loadImage();

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    createAndShowGUI();
                }
            });
           
            ScreenRegion s = new DesktopScreenRegion();
            Thread.sleep(3000);
            ScreenRegion result = s.find(new ImageTarget(new File("c:\\tmp\\383.jpg")));
            // System.out.println("Score: " + result.getScore());
            // System.out.println("State: " + result.getState());
           
            // Construct a Canvas object of the type DesktopCanvas
            Canvas canvas = new DesktopCanvas();
            // Add a box around a screen region 'r'
            canvas.addBox(result);
            // Add a label on the screen region r
            canvas.addLabel(result, "WE FOUND IT!!");
            // Display the canvas for 3 seconds
            canvas.display(3);
           
            // frame.dispose();
           
        } catch (IOException e) {
            // handle exception
        }
    }

    private static void loadImage() throws IOException {       
        bi = ImageIO.read(new File("C:\\tmp\\test_TurnOn.png"));
    }

    private static void createAndShowGUI() {
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        final JPanel panel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                Graphics g2 = g.create();
                g2.drawImage(bi, 0, 0, getWidth(), getHeight(), null);
                g2.dispose();
            }

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(bi.getWidth()/3, bi.getHeight()/3);
            }
        };

        frame.add(panel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        // frame.setLocation(500, 20);
        frame.setVisible(true);
    }
}

Image comparison

2.       Sikuli
3.       OpenCV
4.       http://www.vlfeat.org/
5.    ImageMagic (http://positon.org/compare-diff-between-two-images)

2013年11月4日

汽車安全座椅 Backlog

Britax Marathon70 -> Pavilion 70 G3 -> Advocate70 G3  (歐規: ECE-R44, 1 ~ 7 歲 / 美規:  FMVSS123, 0 ~ 7歲)

代購:

德國:
http://www.kidsroom.de/en_GB (Global Shipping)
http://www.amazon.de/
http://www.maxis-babywelt.de/de/5348/babyausstattung.html

英國:
http://www.amazon.co.uk/
http://www.bambinodirect.co.uk/
http://www.mothercare.com/

瑞典
http://shop.carseat.se/

荷蘭
http://www.babycare.nl/accessories-c-76.html

美國:
http://www.amazon.com/
http://www.albeebaby.com/ 

教學文:
<![if !supportLists]>1.            <![endif]>http://www.mobile01.com/topicdetail.php?f=375&t=2656670
<![if !supportLists]>2.            <![endif]>asmart: http://www.mobile01.com/topicdetail.php?f=375&t=2499939&p=8#33428974
<![if !supportLists]>3.            <![endif]>asmart 番外篇: http://www.mobile01.com/topicdetail.php?f=375&t=2499939&p=51#35754650
<![if !supportLists]>4.            <![endif]>http://www.mobile01.com/topicdetail.php?f=375&t=2470281

2013年6月5日

Launch Android activity by am and passing values

Way1:
1. PC site to launch Android activity by am command:
    adb shell am start -n Packet_Name/Activity_Name -d "parameter"
2. Android site to get the value:
    intentData = getIntent().getDataString();

Way2: (Easy to send multiple parameters)
1. PC site to launch Android activity by am command:
    adb shell am start -n Packet_Name/Activity_Name --es str "parameter "
2. Android site to get the value:
    Intent intent = getIntent();
    String str = intent.getStringExtra("str");

2013年5月21日

Slideshare alternative

http://issuu.com/explore
http://www.hashdoc.com/
http://www.slideshare.net/?ss

2013年3月1日

File sync / backup solution collect (Dropbox alternative)

Function comparison example:
<![if !supportLists]>1.    <![endif]>Backup service: http://en.wikipedia.org/wiki/Comparison_of_online_backup_services
<![if !supportLists]>2.    <![endif]>Synchronization software: http://en.wikipedia.org/wiki/Comparison_of_file_synchronization_software
<![if !supportLists]>3.    <![endif]>http://www.syncplicity.com/products/pricing

Dropbox alternative solutions from some blogs:

Links to some solutions (Seems Good):
<![if !supportLists]>1.    <![endif]>wuala (http://wuala.com/en/download/windows)
<![if !supportLists]>2.    <![endif]>SPIDEROAK (https://spideroak.com/opendownload/)
<![if !supportLists]>3.    <![endif]>Seafile (http://seafile.com/en/home/)
<![if !supportLists]>4.    <![endif]>Syncany (http://www.syncany.org/)

(TBD)
<![if !supportLists]>1.    <![endif]>FTPbox (http://ftpbox.org/)
<![if !supportLists]>2.    <![endif]>ownCloud (http://owncloud.org/)
<![if !supportLists]>3.    <![endif]>sparkleshare (http://sparkleshare.org/)