搜尋此網誌
2014年2月10日
Android UIAutormator - First touch
1. Control and switch between multiple activities of a single app.
2. Control an switch between multiple apps.
3. Combine with API for result checking?
4. User gesture coverage (Single tap, Double tap, Long press, Swipe, Scroll, etc).
5. UI component travel
Study:
2. How to run: http://my.oschina.net/yuchaolee/blog/171289
3. Sample:
b. Calculator:
c. Guadian: http://www.theguardian.com/info/developer-blog/2013/jul/31/robust-testing-uiautomator-android
f. Clock: http://blog.chengyunfeng.com/?p=504 / http://mobileautomation.blogspot.tw/2012/11/android-uiutomater-sample-test-case.html
g.
5. Basic training: http://blog.chengyunfeng.com/?p=504
Step:
1. Create a Java project.
2. Add Junit lib.
3. Add android.jar & uiautomator.jar.
4. Coding.
5. <android-sdk>/tools/android create uitest-project -n <project_name> -t <AVD_ID> -p <project_path> (AVD_ID 透過 android list 取得)
6. Edit build.xml -> line2 ("help" -> "build").
7. build.xml -> ant build
8. adb push xxx.jar /data/local/tmp/
9. adb shell uiautomator runtest xxx.jar -c <Package_name>.<Class_Name>.
2014年2月7日
Java + Android + Sikuli + UIAutomator = Test automation
Project page: https://code.google.com/p/sikuli-api/
Eclipse:
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);
}
}
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/
2013年12月17日
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.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");
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");
訂閱:
文章 (Atom)