Sunday, February 5, 2012

Testing Play! Framework Web App with Netbeans + Selenium RC

Why?
  • Play's selenium test is not reliable since it's flash scope is cleared every 2 seconds (means that test can be success or fail base on the loading time).
  • Upload file not work
What?
How?
  1. Create new Web Application - Call it MyAppSelenium
  2. (If there's no Test Packages label) Right click on project > Properties > Sources look for Test Packages Folders . Create a new folder with test folder name (default 'test') and the same level with 'src'.
  3. Right click on project > Properties > Libraries do Add Library > JUnit for both Compile Tests and Run Tests in two correspond tabs.
  4. Unzip Selenium RC client driver. Right click on project > Properties > Libraries do Add JAR/Folder > select selenium client jar file (e.g. selenium-java-2.18.0.jar) for both Compile Tests and Run Tests.
  5. Right click on Test Packages > New > Java class > testMyApp.java, write your test
  6. Run server 'java -jar selenium-server-***.jar'
  7. Run Play app 'play run myapp'
  8. Right click 'testMyApp.java' > Test File(Ctrl+F6)
Done.

  • Template for writing 'testMyApp.java':
import com.thoughtworks.selenium.*;
import org.junit.*;

public class testMyApp {

    static private String appServerURL = "http://localhost:9000/";

    @Test
    public void testSimple() throws Exception {

        Selenium selBrowser = new DefaultSelenium("localhost", 4444, "*firefox", appServerURL);
        selBrowser.start();
      
        //Home page
        selBrowser.open("/");
        selBrowser.waitForPageToLoad("1000");
        Assert.assertTrue(selBrowser.isTextPresent("Hello World!"));       
        selBrowser.stop();

    }
}
  • Write a play.Unittest (call it 'preTest') and do following in case need to setup data for test.
Fixtures.deleteAll()
Fixtures.load('test-data.yml')
Run 'play test myapp' instead, go to http://localhost:9000/@tests, choose  'preTest' > Start. Back to Netbeans and run your test.






Sunday, December 25, 2011

Errors

* ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
 => service mysql start

Thursday, December 22, 2011

[Collect] How to become mr.invisible

From stackoverflow.com:
  • A Live CD, e.g. one of the Linux variants
  • An internet connection not owned or traceable to you, e.g. an unsecured WiFi connection
  • An SSL VPN with an exit point in a country with laws to protect your information and purchased anonymously e.g. by mail order
  • A browser appropriately configured and with extensions such as noscript and SSLeverywhere, etc. TOR provide a reasonable pre-packaged browser you could use. Tor through the VPN wouldn't be a bad idea either.

Source:
how-anonymous-is-my-setup. Thanks for your answer, lour.



Sunday, December 18, 2011

Thursday, December 15, 2011

[backtrack5] Get your wireless up and running using wicd

(1) Go: Internet -> Wicd Network Manager.
    If error: Could not connect to wicd's D-Bus...Go to (2)
    If wicd cannot recognize your wireless card (eg.cannot find any wireless AP in range (if have)). Go to (3)
    If you try to connect to an AP using WEP and receive "Bad password", check if you enter in passphrase mode or hex mode
    If you try to connect to an AP and receive "Unable To Get IP Address" or "Connection failed: Could not contact the wireless access point" or ...Go to (4)

(2) Take a look at Basic Usage#WICD NetworkManager, notice that you HAVE TO reboot backtrack, and run 2 commands BEFORE starting wicd, if not, it won't work.

(3) Follow the instruction to install wireless driver Wireless Drivers. If your card not in the list, be nice and report it :p

(4) Try one of these until it works
sudo rm /etc/udev/rules.d/70-persistent-net.rules
apt-get install dhcp-client
read line by line from dmesg, notice the dhcp lines to find the problems.

EDIT: 
modprobe -r <driver>
modprobe -s <driver>
restart wicd


Ref:
http://www.backtrack-linux.org/wiki/index.php/Basic_Usage#WICD_Network_Manager
http://www.backtrack-linux.org/wiki/index.php/Wireless_Drivers
http://www.fir3net.com/Debian-/-Ubuntu/configuring-a-wireless-connection-within-backtrack-4-r2.html