Thứ Sáu, 29 tháng 3, 2013

Maven Toan Tap

Đang đánh một dự án sử dụng Maven, cảm thấy cực kỳ ấn tượng với thằng này, nó thật sự rất hay và tiện lợi với các dự án cỡ lớn. OK, giờ chúng ta hãy cùng nhau khám phá Maven nhé


Phần 1: Khái niệm về Maven


Đầu tiên là khái niệm về Maven, Maven là gì, nó có lợi ích gì, cái này các bạn "Gúc" một phát ra đầy rẫy mình chỉ tóm tắt chút đỉnh để mọi người có thể hình dung cơ bản về Maven. Sau đó mình sẽ tiếp vào phần 2 luôn, tính mình không thích lý thuyết dài dòng.

Đối với những Dev nào làm về cách hệ thống lớn, phức tạp sử dụng nhiều thư viện và frame work lại đòi hỏi phải release liên tục cho nên công việc đóng gói (build & deploy), quản lý, nâng cấp và bào trì chúng thực sự rất oải. Ngoài ra việc tích hợp các thư viện mới cũng như quản lý và nâng cấp các thư viện có sẵn là tương đối phức tạp.

Tuy nhiên, những trở ngại nói trên hoàn toàn có thể giải quyết được nhờ vào Apache Maven.

Vậy ưu điểm của Maven là gì đó là:

Tự động hóa toàn bộ quá trình release project, khởi tạo, cập nhật thư viện, build & unit test và release, với một project cỡ lớn thì việc này là tối quan trọng, chỉ cần một sai lầm trong một công đoạn là có để delay cả dự án (lúc đấy thì tha hồ mà OT nhá =)).

Quản lý các dependency (các thư viện) trong project một các ưu việt: tự động cập nhật, mở rộng dễ dàng, đóng gói. Vì thế toàn bộ các file jar thư viện điều được "vứt" cho Maven quản lý điều đó khiến cho dung lượng project của chúng ta nhẹ nhàng đi rất nhiều.

Phân chia 1 project lớn thành các module nhỏ, từ đó cho phép làm việc đồng thời trên các module khác nhau, đồng thời vẫn tạo được tính thống nhất. Không phụ thuộc vào IDE, cho phép chuyển đổi từ Eclipse sang NetBeans, IntelliJ IDEA ... một cách dễ dàng. Mình thấy trong thực thế thấy rất nhiều dự án được nhiều công ty cùng phát triển, mỗi công ty lại phát triển một module và lại có một chuẩn IDE riêng nên Maven quả là một lựa chọn không tồi.

Trong thực tế thì cũng có khá nhiều dự án cũng như các công ty sử dụng Maven như một nền tảng build với những ứng dụng Java Enterprise. Các Dev, các bạn đã khởi đầu với Ant như là Beginner, vậy hãy đến với Maven như một Professional.


Phần 2: Cài đặt Maven.


1. Đầu tiên bạn hãy tải Maven tại địa chỉ: http://maven.apache.org/download.html
Ở đây tôi tải bản 3.0.4 là bản mới nhất tại thời điểm tác giả viết bài này.

2. Giải nén rồi để ở đâu đó tùy bạn, ở đây tôi để Maven tại: C:\apache-maven-3.0.4

3. Thiết lập biến môi trường.

Bạn hãy vào System Properties chọn Environment Variables.



Sau đó chọn New trong mục System variables thiết lập MAVEN_HOME chỉ đến thư mục cài Maven như hình sau.



Sau đó ta hãy thêm (edit) patch cho Maven "%M2_HOME%\bin" trong mục Patch trong mục System variables như trong hình:



Sau đó ta hãy vào Command line (vào run gõ cmd -> enter) thử lệnh maven --version


Nếu như trên hình tức là tức là mọi việc đã được cấu hình chính xác.


Phần 3: Thao tác với Maven trên Eclipse.

Bạn cũng có thể tạo một dự án Maven từ dòng lệnh command line, nhưng ở đây tôi xin phép hướng dẫn thao tác với Maven trên Eclipse. Eclipse mà một IDE tuyệt vời một người bạn không thể thiếu đối với những Java Dev.

Đầu tiên bạn phải tải plugin m2eclispe cho Eclipse tại đây: http://www.eclipse.org/m2e/download/
Ở đây tôi dùng Eclipse mới nhất là bản Eclipse 3.7 (Indigo).
Bạn vào menu Help ấn chọn Install New Software -> điền URL: http://download.eclipse.org/technology/m2e/releases vào mục work with rồi ấn Add -> Gõ tên plugin rồi ấn OK sẽ hiện thị ra như hình sau:



Sau đó việc của bạn là ấn next và chờ plugin cài đặt xong, tranh thủ thư giãn làm cốc caffe cái nhỉ .

Khi plugin cài đặt xong bạn hãy restart lại Eclipse, giờ bạn đã có một công cụ tuyệt với để bắt đầu với một dự án Maven đầu tiên.
Trước khi tạo project bạn hãy config lại thư viện Maven trong eclipse như sau: chọn menu Window -> Preferences -> Maven -> Installations ấn nút Add rồi chỉ đến thư mục cài đặt Maven rồi ấn OK để Eclipse làm việc với Maven mình vừa cài đặt bên trên.



Việc tạo một một Maven bây giờ trở nên dễ hơn ăn kẹo, đơn giản chỉ là chọn New -> Maven project. Trong phần Artifact-Id cho từng loại project khác nhau, ở đây tôi chọn maven-archetype-quickstart



Tiếp theo bạn hãy định nghĩa Group Id, Artifact Id và version cho project ở đây tôi gõ như sau
Group Id: com.iamvtn.maven
Artifact Id: helloworld
Vậy hai thằng này nó có ý nghĩa là gì? Tôi sẽ đề cập trong phần 4: Tìm hiểu các thành phần trong Maven project của bài viết.



Sau khi ấn finish project sẽ có cấu trúc như sau:



Giờ bạn có thể build, clean hay install hoàn toàn trên eclipse bằng cách bạn click chuột phải vào project chọn Run as -> Build, Clean, Install ...
File build được sẽ được lưu vào thư mục target của dự án.

(chú ý hãy enable chức năng Workspace Resolution bằng cách click chuột phải vào project chọn đến menu Maven -> Enable Workspace Resolution)

Phần 4: Tìm hiểu các thành phần trong Maven project.

1. Đầu tiên ta hãy tìm hiểu và file pom.xml, vậy file pom này có ý nghĩa gì mà cách dùng nó thế nào?

Maven dùng khái niệm Project Object Model(POM) để mô tả việc build project, các thành phần phụ thuộc và các module (dependency). Nó định nghĩa trước các target cho việc khai báo task, trình biên dịch, đóng gói và thứ tự hoạt động để mọi việc diến ra tốt nhất. Maven tải các thư viện, plug-in từ 1 hoặc nhiều repositories. Cũng có thể upload các sản phẩm lên repository sau khi đã build xong. Nói chung thì nó là một file config chung cả cả Maven project.

Ta hãy tìm hiểu và mổ xẻ file pom.xml trên project maven ta vừa tạo trên phần 3.

Model version luôn là 4.0.0 với Maven 2.x trở lên
 <modelVersion>4.0.0</modelVersion>

Group ID tương tự như là namespace(tên gói).
 <groupId>com.iamvtn.maven</groupId> 

Đây chính là tên của maven project.
 <artifactId>helloworld</artifactId> 

Định danh version của maven project
 <version>1.0</version>   

Dạng packaging của project có thể là dạng gói jar, pom hay bundle ...
 <packaging>jar</packaging>  

Tên của project
 <name>helloworld</name> 

Đây là nơi gọi các library dependencies ở đây tôi có sử dụng JUnit cho việc viết Unit test
Bạn có thể gọi thêm các library bằng thêm các thẻ dependency vào, vậy đấy việc thêm bớt hay upgrade thư viện chỉ đơn giản là config vài dòng lệnh, khỏe re không các bạn
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
 </dependencies>

Ngoài ra bạn có thể Maven còn có hỗ trợ những plugin vô cùng phong phú ví dụ đơn giản như plugin để complie Java, để dùng nó đơn giản bạn chỉ cần config như sau.
    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
                <version>2.3.2</version>
            </plugin>
        </plugins>
    </build>


Helloworld project vừa tạo mặc định ta có hai phần để chứa các java code đó là src/mail/java để chứa các logic code và src/test/java để chứa các kịch bản Unit test.

Ta hãy xem lớp App.java trong src/mail/java, bạn có thể tự do phát triển và coding tùy ý ở đây.
package com.iamvtn.maven.helloworld;
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

Đáng chú ý là lớp AppTest, ở đây bạn có thể viết các kịch bản test case cho việc unit test, khi Maven build nó sẽ chạy qua tất cả các test case và hiện thị ra thông báo ngay khi đang build. Việc tạo Unit test cho các project là việc rất nên làm.
package com.iamvtn.maven.helloworld;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}



Phần 5. Làm việc với nhiều module với Maven


Như phần 1 đã nói maven có điểm mạnh với việc làm việc với nhiều module, sau đây ta sẽ tìm hiểu cách tạo các module và set các chúng sử dụng lẫn nhau (dependency) như thế nào.

Sau đây tôi sẽ tạo ra 4 module là Model, Persistence, Controller và View, nghe quen nhỉ, he he tôi sẽ tạo một Maven project theo kiến trúc MVC bigsmile.

Đầu tiên để tạo một Maven Module thì Parent project phải có kiểu packaging là pom, ta config lại packaging của helloworld project như sau:
<packaging>pom</packaging>

Sau đó click chuột phải vào helloworld project chọn New -> Maven Module cũng tương tự như tạo Maven project bạn chọn Artifact-Id là maven-archetype-quickstart rồi chọn package name ở đây tôi gõ là com.iamvtn.maven.model.domain

Sau khi Maven module được tạo ta sẽ có cấu trúc project như sau


Khi đó file pom.xml trong parent maven project sẽ thêm vào các module vừa tạo như sau:
 <modules>
  <module>model</module>
 </modules>


Tiếp theo ta sẽ tạo một domain class có tên là Hello có một thuộc tình là String sayHello
package com.iamvtn.helloworld.model.domain;

public class Hello {
 String sayHello;

 /**
  * @return the sayHello
  */
 public String getSayHello() {
  return sayHello;
 }

 /**
  * @param sayHello the sayHello to set
  */
 public void setSayHello(String sayHello) {
  this.sayHello = sayHello;
 } 
}


Tương tự ta cũng sẽ tạo lần lượt tạo thêm module Persistence Module này có tác dụng set dữ liệu cho Hello Object bên trên, để muốn dùng module Model thì trong file pom.xml của Persistence ta sẽ phải dependency đến Model module
        <dependency>
            <groupId>com.iamvtn.maven</groupId>
            <artifactId>model</artifactId>
            <version>1.0</version>
        </dependency>

trong Persistence ta sẽ defince ra một Interface là HelloDao và một class implements là HelloDaoImpl

HelloDao
package com.iamvtn.maven.persistence.dao;

import com.iamvtn.maven.model.domain.Hello;

public interface HelloDao {
 public Hello sayHello ();
}

HelloDaoImpl
package com.iamvtn.maven.persistence.dao.impl;

import com.iamvtn.maven.model.domain.Hello;
import com.iamvtn.maven.persistence.dao.HelloDao;

public class HelloDaoImpl implements HelloDao {

 public Hello sayHello() {
  Hello hello = new Hello();
  hello.setSayHello("Hello");
  return hello;
 }
}


Tương tự ta cũng tạo ra Maven module là Controller, thằng Controller này sử dụng đến lớp Persistence và Model thì trong pom.xml của Controller ta cũng phải khai báo các dependency sau:
        
        <dependency>
            <groupId>com.iamvtn.maven</groupId>
            <artifactId>model</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.iamvtn.maven</groupId>
            <artifactId>persistence</artifactId>
            <version>1.0</version>
        </dependency>


Trong Controller tôi cũng định nghĩa ra một Interface HelloLogicvà một Class implements HelloLogicImpl để thực hiện gọi đến Persistence và lấy ra dữ liệu của sayHello như sau:
HelloLogic:
package com.iamvtn.maven.controller.logic;

public interface HelloLogic {
 public String sayHello();
}

HelloLogicImpl
package com.iamvtn.maven.controller.logic.impl;

import com.iamvtn.maven.controller.logic.HelloLogic;
import com.iamvtn.maven.model.domain.Hello;
import com.iamvtn.maven.persistence.dao.HelloDao;
import com.iamvtn.maven.persistence.dao.impl.HelloDaoImpl;

public class HelloLogicImpl implements HelloLogic {

 public String sayHello() {
  Hello hello = new Hello();
  HelloDao helloDao = new HelloDaoImpl();
  hello = helloDao.sayHello();
  String sayHello = hello.getSayHello();
  return sayHello;
 }

}


Cuối cùng ta tạo một Maven module là View, module này sẽ gọi đến Controller để hiện thị ra sayHello
tương tự ta cũng config trong file pom.xml dependency đến Controller
        <dependency>
            <groupId>com.iamvtn.maven</groupId>
            <artifactId>controller</artifactId>
            <version>1.0</version>
        </dependency>

Và cuối cùng ta sẽ thực hiện gọi đến Controller
package com.iamvtn.maven.view;

import com.iamvtn.maven.controller.logic.HelloLogic;
import com.iamvtn.maven.controller.logic.impl.HelloLogicImpl;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
     HelloLogic helloLogic = new HelloLogicImpl();
     String sayHello = helloLogic.sayHello();
        System.out.println( sayHello );
    }
}


Phù thế là bạn đã thực hiện tạo ra được một Maven project có nhiều các module con hoạt động theo mô hình MVC rồi đấy.

Giờ bạn có thể build project maven và tùy ý sử dụng được rồi.
Có hai cách build một là bạn dùng Eclipse bằng cách click chuột phải vào project rồi chọn Run as -> Maven install



Hoặc sử dụng command line bằng cách gõ lệnh mvn instal



Xem full mã nguồn tại đây: http://files.myopera.com/caffeJava/Code/helloworldmaven.zip

Vừa rồi tôi đã hướng dẫn bạn tìm hiểu cơ bản về Maven, đến đây chỉ mới là cào vào bề mặt của maven, Maven đang chờ bạn khám phá và chia sẻ tiếp đó.

Thứ Năm, 28 tháng 3, 2013

PHPUnit Installation on Wamp in Windows 7 and Integration with Eclipse

In this tutorial we will use wamp server package version 2.2a for installing PHPUnit on. Since there may be some problems with 64-bit version related to PHPUnit installation, it is better to use 32-bit version of it.

First we have to install PEAR.

If you do not have “go-pear.phar” file at your PHP folder you should download it from the “pear.php.net/go-pear.phar” web address, create a folder called “pear” at your PHP folder (for ex: C:\wamp\bin\php\php5.3.8) and then place the “go-pear.phar” file into it. Then open a command prompt and type the following command:
php .\pear\go-pear.phar
By the way, in order not to encounter any problem during command prompt operations, I recommend you to open the command prompt windows with “Run as administrator” option throughout this tutorial.

Just press ENTER as a reply to the following question:


Then press ENTER in order to accept all of the paths listed:


Reply as “Y” to the following question:


Then press ENTER again to finish the installation.


Now your pear installation is completed:


After the installation, add your php directory (for ex: C:\wamp\bin\php\php5.3.8) to the system environment variable “PATH” in order to be able to call “pear.bat” from any location (if you have not added yet before the pear installation).
Moreover, it is better to run “PEAR_ENV” registry file located at your PHP folder (for ex: C:\wamp\bin\php\php5.3.8) in order to add useful environment variables.
From now on we can install PHPUnit using pear. First we can check whether it is updated by the following command:
pear upgrade-all



After we are sure that it is updated, we should add the following channels:

pear channel-discover components.ez.no
pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com



If something goes wrong with the above pear commands you could try the “pear clear-cache” command to make sure that the installer does not use cached data.
Finally, we can install the PHPUnit using the following command:
pear install –alldeps phpunit/PHPUnit

The following components are installed:
phpunit/PHPUnit can optionally use PHP extension “curl”
phpunit/PHPUnit can optionally use PHP extension “dbus”
phpunit/PHPUnit_MockObject can optionally use PHP extension “soap”
pear/HTTP_Request2 can optionally use PHP extension “curl”
pear/HTTP_Request2 can optionally use PHP extension “fileinfo”
pear/HTTP_Request2 can optionally use PHP extension “openssl”
downloading PHPUnit-3.5.15.tgz …
Starting to download PHPUnit-3.5.15.tgz (118,859 bytes)
……………………..done: 118,859 bytes
downloading DbUnit-1.0.3.tgz …
Starting to download DbUnit-1.0.3.tgz (39,292 bytes)
…done: 39,292 bytes
downloading File_Iterator-1.2.6.tgz …
Starting to download File_Iterator-1.2.6.tgz (3,439 bytes)
…done: 3,439 bytes
downloading Text_Template-1.1.0.tgz …
Starting to download Text_Template-1.1.0.tgz (2,783 bytes)
…done: 2,783 bytes
downloading PHP_CodeCoverage-1.0.5.tgz …
Starting to download PHP_CodeCoverage-1.0.5.tgz (115,040 bytes)
…done: 115,040 bytes
downloading PHP_Timer-1.0.2.tgz …
Starting to download PHP_Timer-1.0.2.tgz (3,686 bytes)
…done: 3,686 bytes
downloading PHPUnit_MockObject-1.0.9.tgz …
Starting to download PHPUnit_MockObject-1.0.9.tgz (18,414 bytes)
…done: 18,414 bytes
downloading PHPUnit_Selenium-1.0.3.tgz …
Starting to download PHPUnit_Selenium-1.0.3.tgz (16,587 bytes)
…done: 16,587 bytes
downloading YAML-1.0.6.tgz …
Starting to download YAML-1.0.6.tgz (10,010 bytes)
…done: 10,010 bytes
downloading XML_RPC2-1.1.1.tgz …
Starting to download XML_RPC2-1.1.1.tgz (68,431 bytes)
…done: 68,431 bytes
downloading ConsoleTools-1.6.1.tgz …
Starting to download ConsoleTools-1.6.1.tgz (869,994 bytes)
…done: 869,994 bytes
downloading PHP_TokenStream-1.0.1.tgz …
Starting to download PHP_TokenStream-1.0.1.tgz (7,250 bytes)
…done: 7,250 bytes
downloading HTTP_Request2-2.0.0.tgz …
Starting to download HTTP_Request2-2.0.0.tgz (97,476 bytes)
…done: 97,476 bytes
downloading Cache_Lite-1.7.12.tgz …
Starting to download Cache_Lite-1.7.12.tgz (30,469 bytes)
…done: 30,469 bytes
downloading Base-1.8.tgz …
Starting to download Base-1.8.tgz (236,357 bytes)
…done: 236,357 bytes
downloading Net_URL2-2.0.0.tgz …
Starting to download Net_URL2-2.0.0.tgz (11,325 bytes)
…done: 11,325 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.2.6
install ok: channel://pear.phpunit.de/Text_Template-1.1.0
install ok: channel://pear.phpunit.de/PHP_Timer-1.0.2
install ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.0.3
install ok: channel://pear.symfony-project.com/YAML-1.0.6
install ok: channel://pear.php.net/Cache_Lite-1.7.12
install ok: channel://components.ez.no/Base-1.8
install ok: channel://pear.php.net/Net_URL2-2.0.0
install ok: channel://pear.phpunit.de/DbUnit-1.0.3
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.0.9
install ok: channel://components.ez.no/ConsoleTools-1.6.1
install ok: channel://pear.php.net/HTTP_Request2-2.0.0
install ok: channel://pear.php.net/XML_RPC2-1.1.1
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.0.1
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.0.5
install ok: channel://pear.phpunit.de/PHPUnit-3.5.15
After the installation has finished, we can check the PHPUnit version as follows:


Before the Eclipse integration part, we can check whether it works correctly at the command prompt:



As we have completed PHPUnit installation, it is time to integrate it with Eclipse.
PHPUnit can be integrated into Eclipse environment via “External Tools Configurations” feature of the Eclipse IDE. Firstly, you should open the “External Tools Configurations” window through the path “Run->External Tools-> External Tools Configurations…” as follows:



Here you should select the option and then click on “New launch configuration” button (). Then give “PHPUnit” as the name of the new configuration. Moreover you should specify the path for the “phpunit.bat” file and the path for your unit tests location as below:



The working directory should be set as $(container_loc) via the “Variables…” button in order to adjust the working directory as the absolute file system path of the unit test file:



Lastly, the “Arguments” part of the configuration windows should be set as $(resource_name). This could be set again by the “Variables…” button as below:



After these settings are done, you should apply them and close the window. From now on you can run your phpunit tests by selecting the test file from the explorer and clicking the “Run external Tools” button () which is in this case “Run PHPUnit”:



The results are shown at the “Console” window:



Adnan Kalay
Traceper Team
www.ankara-gtug.org

Install phpunit on windows


Download PHP

Windows downloads of PHP are available here. If you are not sure of which version to get, check out this Stack Overflow page. I used the VC9 thread safe PHP 5.3.10 download.

Install PHP

Once you’ve downloaded the installer, run it and install PHP in C:\php\ (or wherever you like, only remember this path for later). Choose your webserver (or none if you don’t have a webserver installed) and select any additional components as needed, including PEAR.
Once PHP is installed open a command prompt. Check that PHP is set up correctly by running
php -v
It should give you output something like
PHP 5.3.10 (cli) (built: Feb 2 2012 20:27:51)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

If you don’t get this output something has gone wrong with the PHP install or in the modification of your environment variables. Get this fixed before proceeding with the guide.

Install PEAR

In the command prompt, switch to the directory that you installed PHP to by running
cd C:\php\
Then install PEAR by running
go-pear
Press Enter to accept the default when it asks you “Are you installing a system-wide PEAR or a local copy?”
Press Enter again to accept the file layout.
Press Enter to finish.

Install PHPUnit

Run the following commands (they may take a while to update, be patient):
pear channel-update pear.php.net
pear upgrade-all
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear update-channels


To install PHPUnit, run
pear install --alldeps --force phpunit/PHPUnit

To test that PHPUnit was successfully installed, run
phpunit -v

If all is fine, it should print out something like PHPUnit 3.6.10 by Sebastian Bergmann followed by the help contents.

Set PHPUnit to Windows Environment

Click right mouse in My Computer then chose property .

Choice Advance tab --> Environment Variables.

In System variables , choice Path and add C:\wamp\bin\php\php5.2.6.

 

Problems?

If you get a problem with PEAR refusing to install the dependencies for PHPUnit, try running this command: pear clear-cache. If the underlying problem is this error SECURITY ERROR: Will not write to C:\php\...rest.cacheid as it is symlinked to C:\php\...rest.cacheid - Possible symlink attack then clearing the cache should fix it.
If you get stuck with no helpful error messages while installing PHPUnit, check the PHP error log. To locate it, open your php.ini file (c:\php\php.ini) and look for a line like error_log="C:\Windows\temp\php-errors.log". Open the log file at the location specified and look at the bottom of the log for any recent errors. Copy the error message and Google for solutions.

Thứ Tư, 27 tháng 3, 2013

Note Robotium

     1. waitForText(String text)
     * Waits for a text to be shown. Default timeout is 20 seconds.
     * @param text the text to wait for, specified as a regular expression
     * @return {@code true} if text is shown and {@code false} if it is not shown before the timeout   

     2. waitForText(String text, int minimumNumberOfMatches, long timeout)
     * Waits for a text to be shown.
     * @param text the text to wait for, specified as a regular expression
     * @param minimumNumberOfMatches the minimum number of matches that are expected to be shown. {@code 0} means any number of matches
     * @param timeout the the amount of time in milliseconds to wait
     * @return {@code true} if text is shown and {@code false} if it is not shown before the timeout
   
     3.waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll)
     * Waits for a text to be shown.
     * @param text the text to wait for, specified as a regular expression
     * @param minimumNumberOfMatches the minimum number of matches that are expected to be shown. {@code 0} means any number of matches
     * @param timeout the the amount of time in milliseconds to wait
     * @param scroll {@code true} if scrolling should be performed
     * @return {@code true} if text is shown and {@code false} if it is not shown before the timeout
   
     4. waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll, boolean onlyVisible)
     * Waits for a text to be shown.
     * @param text the text to wait for, specified as a regular expression
     * @param minimumNumberOfMatches the minimum number of matches that are expected to be shown. {@code 0} means any number of matches
     * @param timeout the the amount of time in milliseconds to wait
     * @param scroll {@code true} if scrolling should be performed
     * @param onlyVisible {@code true} if only visible text views should be waited for
     * @return {@code true} if text is shown and {@code false} if it is not shown before the timeout
   
     5. waitForView(final Class<T> viewClass)
     * Waits for a View of a certain class to be shown. Default timeout is 20 seconds.
     * @param viewClass the {@link View} class to wait for
     * @return {@code true} if the {@link View} is shown and {@code false} if it is not shown before the timeout
   
     6. waitForView(View view)
     * Waits for a given View to be shown. Default timeout is 20 seconds.
     * @param view the {@link View} object to wait for
     * @return {@code true} if the {@link View} is shown and {@code false} if it is not shown before the timeout

     7. waitForView(View view, int timeout, boolean scroll)
     * Waits for a given View to be shown.
     * @param view the {@link View} object to wait for
     * @param timeout the amount of time in milliseconds to wait
     * @param scroll {@code true} if scrolling should be performed
     * @return {@code true} if the {@link View} is shown and {@code false} if it is not shown before the timeout
   
     8. waitForView(final Class<T> viewClass, final int minimumNumberOfMatches, final int timeout)
     * Waits for a View of a certain class to be shown.
     * @param viewClass the {@link View} class to wait for
     * @param minimumNumberOfMatches the minimum number of matches that are expected to be shown. {@code 0} means any number of matches
     * @param timeout the amount of time in milliseconds to wait
     * @return {@code true} if the {@link View} is shown and {@code false} if it is not shown before the timeout

     9. waitForView(final Class<T> viewClass, final int minimumNumberOfMatches, final int timeout,final boolean scroll)
     * Waits for a View of a certain class to be shown.
     * @param viewClass the {@link View} class to wait for
     * @param minimumNumberOfMatches the minimum number of matches that are expected to be shown. {@code 0} means any number of matches
     * @param timeout the amount of time in milliseconds to wait
     * @param scroll {@code true} if scrolling should be performed
     * @return {@code true} if the {@link View} is shown and {@code false} if it is not shown before the timeout
   
     10. waitForWebElement(By by)
     * Waits for a WebElement. Default timeout is 20 seconds.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @return {@code true} if the {@link WebElement} is shown and {@code false} if it is not shown before the timeout
   
     11. waitForWebElement(By by, int timeout, boolean scroll)
     * Waits for a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param timeout the the amount of time in milliseconds to wait
     * @param scroll {@code true} if scrolling should be performed
     * @return {@code true} if the {@link WebElement} is shown and {@code false} if it is not shown before the timeout
   
     12. waitForWebElement(By by, int minimumNumberOfMatches, int timeout, boolean scroll)
     * Waits for a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param minimumNumberOfMatches the minimum number of matches that are expected to be shown. {@code 0} means any number of matches
     * @param timeout the the amount of time in milliseconds to wait
     * @param scroll {@code true} if scrolling should be performed
     * @return {@code true} if the {@link WebElement} is shown and {@code false} if it is not shown before the timeout
   
     13. waitForCondition(Condition condition, final int timeout)
     * Waits for a condition to be satisfied.
     * @param condition the condition to wait for
     * @param timeout the amount of time in milliseconds to wait
     * @return {@code true} if condition is satisfied and {@code false} if it is not satisfied before the timeout

     14. searchEditText(String text)
     * Searches for a text string in the EditText objects currently shown and returns true if found. Will automatically scroll when needed.
     * @param text the text to search for
     * @return {@code true} if an {@link EditText} with the given text is found or {@code false} if it is not found
   
     15. searchButton(String text)
     * Searches for a Button with the given text string and returns true if at least one Button
     * is found. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @return {@code true} if a {@link Button} with the given text is found and {@code false} if it is not found
   
     16. searchButton(String text, boolean onlyVisible)
     * Searches for a Button with the given text string and returns true if at least one Button
     * is found. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @param onlyVisible {@code true} if only {@link Button} visible on the screen should be searched
     * @return {@code true} if a {@link Button} with the given text is found and {@code false} if it is not found

     17. searchToggleButton(String text)
     * Searches for a ToggleButton with the given text string and returns {@code true} if at least one ToggleButton
     * is found. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @return {@code true} if a {@link ToggleButton} with the given text is found and {@code false} if it is not found

     18. searchButton(String text, int minimumNumberOfMatches)
     * Searches for a Button with the given text string and returns {@code true} if the
     * searched Button is found a given number of times. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
     * matches are expected to be found
     * @return {@code true} if a {@link Button} with the given text is found a given number of times and {@code false}
     * if it is not found
   
     19. searchButton(String text, int minimumNumberOfMatches, boolean onlyVisible)
     * Searches for a Button with the given text string and returns {@code true} if the
     * searched Button is found a given number of times. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
     * matches are expected to be found
     * @param onlyVisible {@code true} if only {@link Button} visible on the screen should be searched
     * @return {@code true} if a {@link Button} with the given text is found a given number of times and {@code false}
     * if it is not found
   
     20. searchToggleButton(String text, int minimumNumberOfMatches)
     * Searches for a ToggleButton with the given text string and returns {@code true} if the
     * searched ToggleButton is found a given number of times. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
     * matches are expected to be found
     * @return {@code true} if a {@link ToggleButton} with the given text is found a given number of times and {@code false}
     * if it is not found
   
     21. searchText(String text)
     * Searches for a text string and returns {@code true} if at least one item
     * is found with the expected text. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @return {@code true} if the search string is found and {@code false} if it is not found

     22. searchText(String text, boolean onlyVisible)
     * Searches for a text string and returns {@code true} if at least one item
     * is found with the expected text. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @param onlyVisible {@code true} if only texts visible on the screen should be searched
     * @return {@code true} if the search string is found and {@code false} if it is not found
   
     23. searchText(String text, int minimumNumberOfMatches)
     * Searches for a text string and returns {@code true} if the searched text is found a given
     * number of times. Will automatically scroll when needed.
     * @param text the text to search for. The parameter will be interpreted as a regular expression
     * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
     * matches are expected to be found
     * @return {@code true} if text string is found a given number of times and {@code false} if the text string
     * is not found

     24. searchText(String text, int minimumNumberOfMatches, boolean scroll)
     * Searches for a text string and returns {@code true} if the searched text is found a given
     * number of times.
     * @param text the text to search for. The parameter will be interpreted as a regular expression.
     * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
     * matches are expected to be found
     * @param scroll {@code true} if scrolling should be performed
     * @return {@code true} if text string is found a given number of times and {@code false} if the text string
     * is not found

     25. searchText(String text, int minimumNumberOfMatches, boolean scroll, boolean onlyVisible)
     * Searches for a text string and returns {@code true} if the searched text is found a given
     * number of times.
     * @param text the text to search for. The parameter will be interpreted as a regular expression.
     * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
     * matches are expected to be found
     * @param scroll {@code true} if scrolling should be performed
     * @param onlyVisible {@code true} if only texts visible on the screen should be searched
     * @return {@code true} if text string is found a given number of times and {@code false} if the text string
     * is not found

     26. setActivityOrientation(int orientation)
     * Sets the Orientation (Landscape/Portrait) for the current activity.
     * @param orientation the orientation to be set. <code>Solo.</code>{@link #LANDSCAPE} for landscape or
     * <code>Solo.</code>{@link #PORTRAIT} for portrait.
   
     27. getCurrentActivity()
     * Returns the current Activity.
     * @return the current Activity
   
     28. assertCurrentActivity(String message, String name)
     * Asserts that the expected Activity is the currently active one.
     * @param message the message that should be displayed if the assert fails
     * @param name the name of the {@link Activity} that is expected to be active e.g. {@code "MyActivity"}

     29. assertCurrentActivity(String message, @SuppressWarnings("rawtypes") Class expectedClass)
     * Asserts that the expected Activity is the currently active one.
     * @param message the message that should be displayed if the assert fails
     * @param expectedClass the {@code Class} object that is expected to be active e.g. {@code MyActivity.class}

     30. assertCurrentActivity(String message, String name, boolean isNewInstance)
     * Asserts that the expected Activity is the currently active one, with the possibility to
     * verify that the expected Activity is a new instance of the Activity.
     * @param message the message that should be displayed if the assert fails
     * @param name the name of the activity that is expected to be active e.g. {@code "MyActivity"}
     * @param isNewInstance {@code true} if the expected {@link Activity} is a new instance of the {@link Activity}

     31. assertCurrentActivity(String message, @SuppressWarnings("rawtypes") Class expectedClass, boolean isNewInstance)
     * Asserts that the expected Activity is the currently active one, with the possibility to
     * verify that the expected Activity is a new instance of the Activity.
     * @param message the message that should be displayed if the assert fails
     * @param expectedClass the {@code Class} object that is expected to be active e.g. {@code MyActivity.class}
     * @param isNewInstance {@code true} if the expected {@link Activity} is a new instance of the {@link Activity}

     32. assertMemoryNotLow()
     * Asserts that the available memory is not considered low by the system.

     33. waitForDialogToOpen(long timeout)
     * Waits for a Dialog to open.
     * @param timeout the amount of time in milliseconds to wait
     * @return {@code true} if the {@link android.app.Dialog} is opened before the timeout and {@code false} if it is not opened

     34. waitForDialogToClose(long timeout)
     * Waits for a Dialog to close.
     * @param timeout the amount of time in milliseconds to wait
     * @return {@code true} if the {@link android.app.Dialog} is closed before the timeout and {@code false} if it is not closed
   
     35. goBack()
     * Simulates pressing the hardware back key.
   
     36. clickOnScreen(float x, float y)
     * Clicks on a given coordinate on the screen.
     * @param x the x coordinate
     * @param y the y coordinate

     37. clickLongOnScreen(float x, float y)
     * Long clicks a given coordinate on the screen.
     * @param x the x coordinate
     * @param y the y coordinate
   
     38. clickLongOnScreen(float x, float y, int time)
     * Long clicks a given coordinate on the screen for a given amount of time.
     * @param x the x coordinate
     * @param y the y coordinate
     * @param time the amount of time to long click
   
     39. clickOnButton(String name)
     * Clicks on a Button with a given text. Will automatically scroll when needed.
     * @param name the name of the {@link Button} presented to the user. The parameter will be interpreted as a regular expression

     40. clickOnImageButton(int index)
     * Clicks on an ImageButton with a given index.
     * @param index the index of the {@link ImageButton} to be clicked. 0 if only one is available

     41. clickOnToggleButton(String name)
     * Clicks on a ToggleButton with a given text.
     * @param name the name of the {@link ToggleButton} presented to the user. The parameter will be interpreted as a regular expression

     42. clickOnMenuItem(String text)
     * Clicks on a MenuItem with a given text.
     * @param text the menu text that should be clicked on. The parameter will be interpreted as a regular expression

     43. clickOnMenuItem(String text, boolean subMenu)
     * Clicks on a MenuItem with a given text.
     * @param text the menu text that should be clicked on. The parameter will be interpreted as a regular expression
     * @param subMenu true if the menu item could be located in a sub menu

     44. clickOnWebElement(WebElement webElement)
     * Clicks on the given WebElement.
     * @param webElement the WebElement to click

     45. clickOnWebElement(By by)
     * Clicks on a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")

     46. clickOnWebElement(By by, int match)
     * Clicks on a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param match if multiple objects match, this determines which one will be clicked

     47. clickOnWebElement(By by, int match, boolean scroll)
     * Clicks on a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param match if multiple objects match, this determines which one will be clicked
     * @param scroll {@code true} if scrolling should be performed

     48. void pressMenuItem(int index)
     * Presses a MenuItem with a given index. Index {@code 0} is the first item in the
     * first row, Index {@code 3} is the first item in the second row and
     * index {@code 6} is the first item in the third row.
     * @param index the index of the {@link android.view.MenuItem} to be pressed

     49. pressMenuItem(int index, int itemsPerRow)
     * Presses a MenuItem with a given index. Supports three rows with a given amount
     * of items. If itemsPerRow equals 5 then index 0 is the first item in the first row,
     * index 5 is the first item in the second row and index 10 is the first item in the third row.
     * @param index the index of the {@link android.view.MenuItem} to be pressed
     * @param itemsPerRow the amount of menu items there are per row.  

     50. pressSpinnerItem(int spinnerIndex, int itemIndex)
     * Presses on a Spinner (drop-down menu) item.
     * @param spinnerIndex the index of the {@link Spinner} menu to be used
     * @param itemIndex the index of the {@link Spinner} item to be pressed relative to the currently selected item
     * A Negative number moves up on the {@link Spinner}, positive moves down
   
     51. clickOnView(View view)
     * Clicks on a given View.
     * @param view the {@link View} to be clicked

     52. clickOnView(View view, boolean immediately)
     * Clicks on a given View.
     * @param view the {@link View} to be clicked
     * @param immediately true if view is to be clicked without any wait

     53. clickLongOnView(View view)
     * Long clicks on a given View.
     * @param view the {@link View} to be long clicked

     54. clickLongOnView(View view, int time)
     * Long clicks on a given View for a given amount of time.
     * @param view the {@link View} to be long clicked
     * @param time the amount of time to long click

     55. clickOnText(String text)
     * Clicks on a View displaying a given
     * text. Will automatically scroll when needed.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression

     56. clickOnText(String text, int match)
     * Clicks on a View displaying a given text. Will automatically scroll when needed.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression
     * @param match if multiple objects match the text, this determines which one will be clicked

     57. clickOnText(String text, int match, boolean scroll)
     * Clicks on a View displaying a given text.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression
     * @param match if multiple objects match the text, this determines which one will be clicked
     * @param scroll true if scrolling should be performed
   
     58. void clickLongOnText(String text)
     * Long clicks on a given View. Will automatically scroll when needed. {@link #clickOnText(String)} can then be
     * used to click on the context menu items that appear after the long click.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression

     59 . clickLongOnText(String text, int match)
     * Long clicks on a given View. Will automatically scroll when needed. {@link #clickOnText(String)} can then be
     * used to click on the context menu items that appear after the long click.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression
     * @param match if multiple objects match the text, this determines which one will be clicked

     60. clickLongOnText(String text, int match, boolean scroll)
     * Long clicks on a given View. {@link #clickOnText(String)} can then be
     * used to click on the context menu items that appear after the long click.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression
     * @param match if multiple objects match the text, this determines which one will be clicked
     * @param scroll true if scrolling should be performed

     61. clickLongOnText(String text, int match, int time)
     * Long clicks on a given View. {@link #clickOnText(String)} can then be
     * used to click on the context menu items that appear after the long click.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression
     * @param match if multiple objects match the text, this determines which one will be clicked
     * @param time the amount of time to long click

     62. clickLongOnTextAndPress(String text, int index)
     * Long clicks on a given View and then selects
     * an item from the context menu that appears. Will automatically scroll when needed.
     * @param text the text to be clicked. The parameter will be interpreted as a regular expression
     * @param index the index of the menu item to be pressed. {@code 0} if only one is available

     63. clickOnButton(int index)
     * Clicks on a Button with a given index.
     * @param index the index of the {@link Button} to be clicked. {@code 0} if only one is available

     64. clickOnRadioButton(int index)
     * Clicks on a RadioButton with a given index.
     * @param index the index of the {@link RadioButton} to be clicked. {@code 0} if only one is available

     65. clickOnCheckBox(int index)
     * Clicks on a CheckBox with a given index.
     * @param index the index of the {@link CheckBox} to be clicked. {@code 0} if only one is available

     66. clickOnEditText(int index)
     * Clicks on an EditText with a given index.
     * @param index the index of the {@link EditText} to be clicked. {@code 0} if only one is available

     67. clickInList(int line)
     * Clicks on a given list line and returns an ArrayList of the TextView objects that
     * the list line is showing. Will use the first ListView it finds.
     * @param line the line to be clicked
     * @return an {@code ArrayList} of the {@link TextView} objects located in the list line

     68. clickInList(int line, int index)
     * Clicks on a given list line on a specified ListView and
     * returns an ArrayList of the TextView objects that the list line is showing.
     * @param line the line to be clicked
     * @param index the index of the list. 1 if two lists are available
     * @return an {@code ArrayList} of the {@link TextView} objects located in the list line

     69. clickLongInList(int line)
     * Long clicks on a given list line and returns an ArrayList of the TextView objects that
     * the list line is showing. Will use the first ListView it finds.
     * @param line the line to be clicked
     * @return an {@code ArrayList} of the {@link TextView} objects located in the list line

     70. clickLongInList(int line, int index)
     * Long clicks on a given list line on a specified ListView and
     * returns an ArrayList of the TextView objects that the list line is showing.
     * @param line the line to be clicked
     * @param index the index of the list. 1 if two lists are available
     * @return an {@code ArrayList} of the {@link TextView} objects located in the list line

     71. clickLongInList(int line, int index, int time)
     * Long clicks on a given list line on a specified ListView and
     * returns an ArrayList of the TextView objects that the list line is showing.
     * @param line the line to be clicked
     * @param index the index of the list. 1 if two lists are available
     * @param time the amount of time to long click
     * @return an {@code ArrayList} of the {@link TextView} objects located in the list line

     72. clickOnActionBarItem(int resourceId)
     * Clicks on an ActionBar item with a given resource id.
     * @param resourceId the R.id of the ActionBar item

     73. clickOnActionBarHomeButton()
     * Clicks on an ActionBar Home/Up button.

     74. drag(float fromX, float toX, float fromY, float toY, int stepCount)
     * Simulate touching a given location and dragging it to a new location.
     * This method was copied from {@code TouchUtils.java} in the Android Open Source Project, and modified here.
     * @param fromX X coordinate of the initial touch, in screen coordinates
     * @param toX X coordinate of the drag destination, in screen coordinates
     * @param fromY X coordinate of the initial touch, in screen coordinates
     * @param toY Y coordinate of the drag destination, in screen coordinates
     * @param stepCount How many move steps to include in the drag

     75. scrollDown()
     * Scrolls down the screen.
     * @return {@code true} if more scrolling can be done and {@code false} if it is at the end of
     * the screen
    
     76. scrollToBottom()
     * Scrolls to the bottom of the screen.

     77. scrollUp()
     * Scrolls up the screen.
     * @return {@code true} if more scrolling can be done and {@code false} if it is at the top of
     * the screen

     78. scrollToTop()
     * Scrolls to the top of the screen.
   
     79. scrollDownList(AbsListView list)
     * Scrolls down a given ListView.
     * @param list the {@link AbsListView} to be scrolled
     * @return {@code true} if more scrolling can be done
   
     80. scrollListToBottom(AbsListView list)
     * Scrolls to the bottom of a given ListView.
     * @param list the {@link AbsListView} to be scrolled
     * @return {@code true} if more scrolling can be done

     81. scrollUpList(AbsListView list)
     * Scrolls up a given ListView.
     * @param list the {@link AbsListView} to be scrolled
     * @return {@code true} if more scrolling can be done

     82. scrollListToTop(AbsListView list)
     * Scrolls to the top of a given ListView.
     * @param list the {@link AbsListView} to be scrolled
     * @return {@code true} if more scrolling can be done

     83. scrollDownList(int index)
     * Scrolls down a ListView with a given index.
     * @param index the {@link ListView} to be scrolled. {@code 0} if only one list is available
     * @return {@code true} if more scrolling can be done

     84. scrollListToBottom(int index)
     * Scrolls a ListView with a given index to the bottom.
     * @param index the {@link ListView} to be scrolled. {@code 0} if only one list is available
     * @return {@code true} if more scrolling can be done
   
     85. scrollUpList(int index)
     * Scrolls up a ListView with a given index.
     * @param index the {@link ListView} to be scrolled. {@code 0} if only one list is available
     * @return {@code true} if more scrolling can be done
   
     86. scrollListToTop(int index)
        * Scrolls a ListView with a given index to the top.
        * @param index the {@link ListView} to be scrolled. {@code 0} if only one list is available
        * @return {@code true} if more scrolling can be done

        87. scrollListToLine(AbsListView absListView, int line)
     * Scroll the given ListView to a given line.
     * @param absListView the {@link AbsListView} to scroll
     * @param line the line to scroll to

        88. scrollListToLine(int index, int line)
     * Scroll a ListView with a given index to a given line.
     * @param index the index of the {@link AbsListView} to scroll
     * @param line the line to scroll to

     89. scrollToSide(int side)
     * Scrolls horizontally.
     * @param side the side to which to scroll; {@link #RIGHT} or {@link #LEFT}

     90.scrollViewToSide(View view, int side)
     * Scrolls a View horizontally.
     * @param view the View to scroll
     * @param side the side to scroll; {@link #RIGHT} or {@link #LEFT}

     91. setDatePicker(int index, int year, int monthOfYear, int dayOfMonth)
     * Sets the date in a DatePicker with a given index.
     * @param index the index of the {@link DatePicker}. {@code 0} if only one is available
     * @param year the year e.g. 2011
     * @param monthOfYear the month which starts from zero e.g. 0 for January
     * @param dayOfMonth the day e.g. 10

     92. setDatePicker(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth)
     * Sets the date in a given DatePicker.
     * @param datePicker the {@link DatePicker} object.
     * @param year the year e.g. 2011
     * @param monthOfYear the month which starts from zero e.g. 03 for April
     * @param dayOfMonth the day e.g. 10

     93. setTimePicker(int index, int hour, int minute)
     * Sets the time in a TimePicker with a given index.
     * @param index the index of the {@link TimePicker}. {@code 0} if only one is available
     * @param hour the hour e.g. 15
     * @param minute the minute e.g. 30

     94. setTimePicker(TimePicker timePicker, int hour, int minute)
     * Sets the time in a given TimePicker.
     * @param timePicker the {@link TimePicker} object.
     * @param hour the hour e.g. 15
     * @param minute the minute e.g. 30
   
     95. setProgressBar(int index, int progress)
     * Sets the progress of a ProgressBar with a given index. Examples are SeekBar and RatingBar.
     * @param index the index of the {@link ProgressBar}
     * @param progress the progress that the {@link ProgressBar} should be set to

     96. setProgressBar(ProgressBar progressBar, int progress)
     * Sets the progress of a given ProgressBar. Examples are SeekBar and RatingBar.
     * @param progressBar the {@link ProgressBar}
     * @param progress the progress that the {@link ProgressBar} should be set to

     97. setSlidingDrawer(int index, int status)
     * Sets the status of a SlidingDrawer with a given index. Examples are Solo.CLOSED and Solo.OPENED.
     * @param index the index of the {@link SlidingDrawer}
     * @param status the status that the {@link SlidingDrawer} should be set to

     98. setSlidingDrawer(SlidingDrawer slidingDrawer, int status)
     * Sets the status of a given SlidingDrawer. Examples are Solo.CLOSED and Solo.OPENED.
     * @param slidingDrawer the {@link SlidingDrawer}
     * @param status the status that the {@link SlidingDrawer} should be set to

     99. enterText(int index, String text)
     * Enters text in an EditText with a given index.
     * @param index the index of the {@link EditText}. {@code 0} if only one is available
     * @param text the text string to enter into the {@link EditText} field

     100. enterText(EditText editText, String text)
     * Enters text in a given EditText.
     * @param editText the {@link EditText} to enter text into
     * @param text the text string to enter into the {@link EditText} field

     101. enterTextInWebElement(By by, String text)
     * Enters text in a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param text the text to enter

     102. typeText(int index, String text)
     * Types text in an EditText with a given index.
     * @param index the index of the {@link EditText}. {@code 0} if only one is available
     * @param text the text string to type in the {@link EditText} field

     103. typeText(EditText editText, String text)
     * Types text in a given EditText.
     * @param editText the {@link EditText} to type text in
     * @param text the text string to type in the {@link EditText} field

     104. typeTextInWebElement(By by, String text)
     * Types text in a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param text the text to enter

     105. typeTextInWebElement(By by, String text, int match)
     * Types text in a WebElement.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param text the text to enter
     * @param match if multiple objects match, this determines which one will be typed in
   
     106. typeTextInWebElement(WebElement webElement, String text)
     * Types text in a WebElement.
     * @param webElement the WebElement to type text in
     * @param text the text to enter

     107. clearEditText(int index)
     * Clears the value of an EditText.
     * @param index the index of the {@link EditText} that should be cleared. 0 if only one is available
   
     108. clearEditText(EditText editText)
     * Clears the value of an EditText.
     * @param editText the {@link EditText} that should be cleared

     109. clearTextInWebElement(By by)
     * Clears text in a web element.
     * @param by the By object. Examples are By.id("id") and By.name("name")

     110. clickOnImage(int index)
     * Clicks on an ImageView with a given index.
     * @param index the index of the {@link ImageView} to be clicked. {@code 0} if only one is available

     111. getEditText(int index)
     * Returns an EditText with a given index.
     * @param index the index of the {@link EditText}. {@code 0} if only one is available
     * @return the {@link EditText} with a specified index or {@code null} if index is invalid

     112. getButton(int index)
     * Returns a Button with a given index.
     * @param index the index of the {@link Button}. {@code 0} if only one is available
     * @return the {@link Button} with a specified index or {@code null} if index is invalid

     113. getText(int index)
     * Returns a TextView with a given index.
     * @param index the index of the {@link TextView}. {@code 0} if only one is available
     * @return the {@link TextView} with a specified index or {@code null} if index is invalid

     114. getImage(int index)
     * Returns an ImageView with a given index.
     * @param index the index of the {@link ImageView}. {@code 0} if only one is available
     * @return the {@link ImageView} with a specified index or {@code null} if index is invalid
   
     115. getImageButton(int index)
     * Returns an ImageButton with a given index.
     * @param index the index of the {@link ImageButton}. {@code 0} if only one is available
     * @return the {@link ImageButton} with a specified index or {@code null} if index is invalid

     116. getText(String text)
     * Returns a TextView which shows a given text.
     * @param text the text that is shown, specified as a regular expression
     * @return the {@link TextView} that shows the given text

     117. getText(String text, boolean onlyVisible)
     * Returns a TextView which shows a given text.
     * @param text the text that is shown, specified as a regular expression
     * @param onlyVisible {@code true} if only visible texts on the screen should be returned
     * @return the {@link TextView} that shows the given text

     118. getButton(String text)
     * Returns a Button which shows a given text.
     * @param text the text that is shown, specified as a regular expression
     * @return the {@link Button} that shows the given text

     119. getButton(String text, boolean onlyVisible)
     * Returns a Button which shows a given text.
     * @param text the text that is shown, specified as a regular expression
     * @param onlyVisible {@code true} if only visible buttons on the screen should be returned
     * @return the {@link Button} that shows the given text

     120. getEditText(String text)
     * Returns an EditText which shows a given text.
     * @param text the text that is shown, specified as a regular expression
     * @return the {@link EditText} which shows the given text

     121. getEditText(String text, boolean onlyVisible)
     * Returns an EditText which shows a given text.
     * @param text the text that is shown, specified as a regular expression
     * @param onlyVisible {@code true} if only visible EditTexts on the screen should be returned
     * @return the {@link EditText} which shows the given text

     122. getView(int id)
     * Returns a View with a given resource id.
     * @param id the R.id of the {@link View} to be returned
     * @return a {@link View} with a given id

     123. getView(int id, int index)
     * Returns a View with a given resource id and index.
     * @param id the R.id of the {@link View} to be returned
     * @param index the index of the {@link View}. {@code 0} if only one is available
     * @return a {@link View} with a given id and index

     124. getView(Class<T> viewClass, int index)
     * Returns a View of a given class and index.
     * @param viewClass the class of the requested view
     * @param index the index of the {@link View}. {@code 0} if only one is available
     * @return a {@link View} with a given class and index

     125. getWebElement(By by, int index)
     * Returns a WebElement with a given index
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @param index the index of the {@link WebElement}. {@code 0} if only one is available
     * @return a {@link WebElement} with a given index

     126. getWebUrl()
     * Returns the current web page URL.
     * @return the current web page URL

     127. getCurrentViews()
     * Returns an ArrayList of the Views currently shown in the focused Activity or Dialog.
     * @return an {@code ArrayList} of the {@link View} objects currently shown in the
     * focused window

     128. getCurrentViews(Class<T> classToFilterBy)
     * Returns an ArrayList of Views of the specified Class located in the focused Activity or Dialog.
     * @param classToFilterBy return all instances of this class. Examples are {@code Button.class} or {@code ListView.class}
     * @return an {@code ArrayList} of {@code View}s of the specified {@code Class} located in the current {@code Activity}

     129. getCurrentViews(Class<T> classToFilterBy, View parent)
     * Returns an ArrayList of Views of the specified Class located under the specified parent.
     * @param classToFilterBy return all instances of this class. Examples are {@code Button.class} or {@code ListView.class}
     * @param parent the parent {@code View} for where to start the traversal
     * @return an {@code ArrayList} of {@code View}s of the specified {@code Class} located under the specified {@code parent}

     130.getCurrentWebElements()
     * Returns an ArrayList of WebElements currently shown in the active WebView.
     * @return an {@code ArrayList} of the {@link WebElement} objects currently shown in the active WebView

     131. getCurrentWebElements(By by)
     * Returns an ArrayList of WebElements of the specified By object currently shown in the active WebView.
     * @param by the By object. Examples are By.id("id") and By.name("name")
     * @return an {@code ArrayList} of the {@link WebElement} objects currently shown in the active WebView

     132. isRadioButtonChecked(int index)
     * Checks if a RadioButton with a given index is checked.
     * @param index of the {@link RadioButton} to check. {@code 0} if only one is available
     * @return {@code true} if {@link RadioButton} is checked and {@code false} if it is not checked

     133. isRadioButtonChecked(String text)
     * Checks if a RadioButton with a given text is checked.
     * @param text the text that the {@link RadioButton} shows, specified as a regular expression
     * @return {@code true} if a {@link RadioButton} with the given text is checked and {@code false} if it is not checked

     134. isCheckBoxChecked(int index)
     * Checks if a CheckBox with a given index is checked.
     * @param index of the {@link CheckBox} to check. {@code 0} if only one is available
     * @return {@code true} if {@link CheckBox} is checked and {@code false} if it is not checked

     135. isToggleButtonChecked(String text)
     * Checks if a ToggleButton with a given text is checked.
     * @param text the text that the {@link ToggleButton} shows, specified as a regular expression
     * @return {@code true} if a {@link ToggleButton} with the given text is checked and {@code false} if it is not checked

     136. isToggleButtonChecked(int index)
     * Checks if a ToggleButton with a given index is checked.
     * @param index of the {@link ToggleButton} to check. {@code 0} if only one is available
     * @return {@code true} if {@link ToggleButton} is checked and {@code false} if it is not checked

     137. isCheckBoxChecked(String text)
     * Checks if a CheckBox with a given text is checked.
     * @param text the text that the {@link CheckBox} shows, specified as a regular expression
     * @return {@code true} if a {@link CheckBox} with the given text is checked and {@code false} if it is not checked

     138. isTextChecked(String text)
     * Checks if the given text is checked.
     * @param text the text that the {@link CheckedTextView} or {@link CompoundButton} objects show, specified as a regular expression
     * @return {@code true} if the given text is checked and {@code false} if it is not checked

     139. isSpinnerTextSelected(String text)
     * Checks if a given text is selected in any Spinner located in the current screen.
     * @param text the text that is expected to be selected, specified as a regular expression
     * @return {@code true} if the given text is selected in any {@link Spinner} and false if it is not

     140. isSpinnerTextSelected(int index, String text)
     * Checks if a given text is selected in a given Spinner.
     * @param index the index of the spinner to check. {@code 0} if only one spinner is available
     * @param text the text that is expected to be selected, specified as a regular expression
     * @return true if the given text is selected in the given {@link Spinner} and false if it is not

     141. sendKey(int key)
     * Sends a key: Right, Left, Up, Down, Enter, Menu or Delete.
     * @param key the key to be sent. Use {@code Solo.}{@link #RIGHT}, {@link #LEFT}, {@link #UP}, {@link #DOWN},
     * {@link #ENTER}, {@link #MENU}, {@link #DELETE}

     142. goBackToActivity(String name)
     * Returns to the given Activity.
     * @param name the name of the {@link Activity} to return to, e.g. {@code "MyActivity"}

     143. waitForActivity(String name)
     * Waits for the given Activity. Default timeout is 20 seconds.
     * @param name the name of the {@code Activity} to wait for e.g. {@code "MyActivity"}
     * @return {@code true} if {@code Activity} appears before the timeout and {@code false} if it does not

     144. waitForActivity(String name, int timeout)
     * Waits for the given Activity.
     * @param name the name of the {@link Activity} to wait for e.g. {@code "MyActivity"}
     * @param timeout the amount of time in milliseconds to wait
     * @return {@code true} if {@link Activity} appears before the timeout and {@code false} if it does not

     145. waitForActivity(Class<? extends Activity> activityClass)
     * Waits for the given Activity. Default timeout is 20 seconds.
     * @param activityClass the class of the {@code Activity} to wait for
     * @return {@code true} if {@code Activity} appears before the timeout and {@code false} if it does not

    146. waitForActivity(Class<? extends Activity> activityClass, int timeout)
     * Waits for the given Activity.
     * @param activityClass the class of the {@code Activity} to wait for e.g. {@code "MyActivity"}
     * @param timeout the amount of time in milliseconds to wait
     * @return {@code true} if {@link Activity} appears before the timeout and {@code false} if it does not

     147. waitForFragmentByTag(String tag)
     * Waits for a Fragment with a given tag to appear. Default timeout is 20 seconds.
     * @param tag the name of the tag   
     * @return true if fragment appears and false if it does not appear before the timeout

     148. waitForFragmentByTag(String tag, int timeout)
     * Waits for a Fragment with a given tag to appear.
     * @param tag the name of the tag   
     * @param timeout the amount of time in milliseconds to wait
     * @return true if fragment appears and false if it does not appear before the timeout

     149. waitForFragmentById(int id)
     * Waits for a Fragment with a given id to appear. Default timeout is 20 seconds.
     * @param id the id of the fragment   
     * @return true if fragment appears and false if it does not appear before the timeout

     150. waitForFragmentById(int id, int timeout)
     * Waits for a Fragment with a given id to appear.
     * @param id the id of the fragment   
     * @param timeout the amount of time in milliseconds to wait
     * @return true if fragment appears and false if it does not appear before the timeout

     151. waitForLogMessage(String logMessage)
     * Waits for a log message to appear. Default timeout is 20 seconds.
     * Requires read logs permission (android.permission.READ_LOGS) in AndroidManifest.xml of the application under test.
     * @param logMessage the log message to wait for
     * @return true if log message appears and false if it does not appear before the timeout

     152. waitForLogMessage(String logMessage, int timeout)
     * Waits for a log message to appear.
     * Requires read logs permission (android.permission.READ_LOGS) in AndroidManifest.xml of the application under test.
     * @param logMessage the log message to wait for
     * @param timeout the amount of time in milliseconds to wait
     * @return true if log message appears and false if it does not appear before the timeout

     153. getString(int resId)
     * Returns a localized string.
     * @param resId the resource id of the string
     * @return the localized string
   
     154.sleep(int time)
     * Robotium will sleep for a specified time.
     * @param time the time in milliseconds that Robotium should sleep

     155.finalize()
     * Finalizes the solo object and removes the ActivityMonitor.
     * @see #finishOpenedActivities() finishOpenedActivities() to close the activities that have been active.
    public void finalize() throws Throwable {
        activityUtils.finalize();
    }
   
     156. finishOpenedActivities()
     * The activities that are alive are finished. Usually used in tearDown().

     157. takeScreenshot()
     * Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/".
     * Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.

     158. takeScreenshot(String name)
     * Takes a screenshot and saves it with a given name in "/sdcard/Robotium-Screenshots/".
     * Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.
     * @param name the name to give the screenshot

     159. takeScreenshot(String name, int quality)
     * Takes a screenshot and saves it with a given name in "/sdcard/Robotium-Screenshots/".
     * Requires write permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under test.
     * @param name the name to give the screenshot
     * @param quality the compression rate. From 0 (compress for lowest size) to 100 (compress for maximum quality).

Học lập trình web căn bản với PHP

Bài 1: Các kiến thức căn bản Part 1:  https://jimmyvan88.blogspot.com/2012/05/can-ban-lap-trinh-web-voi-php-bai-1-cac.html Part 2:  https://...