Advertise

Saturday, October 31, 2009

mysqladmin command to change root password

Hi All

If you people wanted to change mysql root password . Please use below mentioned
Procedure.First login into the terminal then issue below mentioned command to change password.
Hope this will help someone who wanted to change mysql root password and this root password is different from linux PC root Login Password


$ mysqladmin -u root password xyznewpassword
However, if you want to change (or update) a root password, then you need to use following command
$ mysqladmin -u root -p oldpassword newpass
Enter password:

Reliance USB Data Card (Huawei) on Ubuntu HowTo

This is a quick way to setup huawei usb data card with reliance connection on ubuntu 8.04 hardy Ram kumar

1. Connect the reliance usb modem and check if its been recognized by the kernel.
$ cat /proc/bus/usb/devices
you’ll see something like this.
T: Bus=02 Lev=01 Prnt=01 Port=05 Cnt=02 Dev#= 4 Spd=12 MxCh= 0
D: Ver= 1.01 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=16 #Cfgs= 1
P: Vendor=12d1 ProdID=1001 Rev= 0.00
S: Manufacturer=Huawei Technologies
S: Product=Huawei Mobile
S: SerialNumber=HUAWEI EC3X1
C:* #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=pl2303
E: Ad=81(I) Atr=03(Int.) MxPS= 16 Ivl=128ms
E: Ad=8a(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=0b(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
I: If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=pl2303
E: Ad=83(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=06(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
2. Modprobe the driver
$ modprobe usbserial vendor=0×12d1 product=0×1001
verify dmesg
$ dmesg
[ 2315.412106] usbcore: registered new interface driver usbserial
[ 2315.412508] drivers/usb/serial/usb-serial.c: USB Serial support registered for generic
[ 2315.461938] usbcore: registered new interface driver usbserial_generic
[ 2315.461945] drivers/usb/serial/usb-serial.c: USB Serial Driver core
[ 2315.480382] drivers/usb/serial/usb-serial.c: USB Serial support registered for pl2303
[ 2315.480414] pl2303 2-6:1.0: pl2303 converter detected
[ 2315.480608] usb 2-6: pl2303 converter now attached to ttyUSB0
[ 2315.480620] pl2303 2-6:1.1: pl2303 converter detected
[ 2315.480691] usb 2-6: pl2303 converter now attached to ttyUSB1
3. Edit /etc/wvdial.conf add the entries provided in the sample file.
or replace the original one with it if there is nothing setup.
It will create a connection called “cdma”
Add the following lines to /etc/wvdial.conf
#/etc/wvdial.conf
[Modem0]
Modem = /dev/ttyUSB0
Baud = 115200
SetVolume = 0
Dial Command = ATDT
Init1 = ATZ
FlowControl = Hardware (CRTSCTS)
[Dialer cdma]
Username =
Password =
Phone = #777
Stupid Mode = 1
Inherits = Modem0
The following things automate recognizing and adding your card everytime you plug it in.
5. Edit/add this file /etc/hotplug/usb/datacard.usermap with following contents
# /etc/hotplug/usb/datacard.usermap
# Huawei EC321 CDMA data card
datacard 0×0003 0×12d1 0×1001
6. Edit/Add /etc/hotplug/usb/datacard . make it executable (chmod +x) . Add the following lines to
it.
#!/bin/bash
#This script goes to ” /etc/hotplug/usb/datacard “
# used to run modprobe when the usb cable is connected
SED=/bin/sed
if [ "$ACTION" = "add" ] && [ -f "$DEVICE" ]
then
VENDOR=”`echo “$PRODUCT” | $SED “s/^\(.*\)\/.*\/.*$/\1/”`”;
PRODUCT_ID=”`echo “$PRODUCT” | $SED “s/^.*\/\(.*\)\/.*$/\1/”`”;
modprobe usbserial “vendor=0x$VENDOR” “product=0x$PRODUCT_ID”
fi

Startx Error Unable to See Graphical Display in Linux

Solution

Please Enter into runlevel 3 then issue the Below command that should fix the issue
#system --reconfig --set-resolution=1024x768 --set-depth=16 --set-driver=nv

Can't connect to local MySQL server through socket '/var/lib /mysql/mysql.sock' (2)

Problem:
phpAdmin
#2002 - The server is not responding (or the local MySQL server's socket is not correctly
configured)
Open phpMyAdmin in New window
Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0 Warning:
Unknown: Failed to write session data (files). Please verify that the current setting of
session.save_path is correct () in Unknown on line 0
http://localhost/projects/myadmin/
mysql login
user: root
password: ""
Solution: Just create enough space in the partition and start mysql service this will fix issuse

How to Access USB Drive In Linux

Hi All

First Step is to Insert PenDrive into Any Linux PC.Then
Open the Terminal and type Below Commands

#fdisk -l

ram@ram-laptop:~$ sudo fdisk -l
[sudo] password for ram:

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000080

Device Boot Start End Blocks Id System
/dev/sda1 * 1 5099 40957686 7 HPFS/NTFS
/dev/sda2 5100 19457 115330635 f W95 Ext'd (LBA)
/dev/sda5 5100 9561 35840983+ 7 HPFS/NTFS
/dev/sda6 9562 19048 76204296 83 Linux
/dev/sda7 19049 19457 3285261 82 Linux swap / Solaris

Disk /dev/sdb: 4022 MB, 4022337536 bytes
255 heads, 63 sectors/track, 489 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0105a552

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 490 3928032+ b W95 FAT32
Partition 1 has different physical/logical endings:
phys=(488, 254, 63) logical=(489, 5, 28)



Here in the above List Look for Last Device that Got Detected By Linux PC.It would be FAT32

Then Next Step is to Mount the Device /dev/sdb1(Note it could vary in each user case) to any Folder in your PC As mentioned in the Below Mentioned Example.

#mount /dev/sdb1 /mnt
#cd /mnt
#ls


Here in my case i am mounting my Device to /mnt Directory .

How to Use VI Editor

Below is the Usefull tips to Operate VI Editor.
1) Press "i" to insert some data .
2) Press Escape twice and and type ":wq" and hit Enter to save and Exit.
3) To Undo the Work Press "u"

Sunday, October 25, 2009

Selenium Get Attribute of Fields

Selenium Get Attribute of Fields

Below is an Example to get Attribute of Text Box using Selenium :




package Selenium;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.SeleniumServer;
public class Main_Test extends SeleneseTestCase {

public void setUp() throws Exception {
/*
* Startting Selenium Server from Test Case itself
* */
SeleniumServer s = new SeleniumServer();
s.start();

/*
* Opening Google web page in Firefox
* */
setUp("http://www.google.co.in//", "*firefox");

}
public void testNew() {

selenium.open("http://www.google.co.in//");

/*
* Getting Property of Text Field like maxlength and size of Text Field
*
* */

String collectTextProperty = selenium.getEval("var property = new Array(); " +
"property[0] = window.document.getElementsByName('q')[0].maxLength;" +
"property[1] = window.document.getElementsByName('q')[0].size; property.toString();");
/* Replace getElementsByName('q') in this 'q' by element id of Textbox*/

String[] Textproperties = collectTextProperty.split(",");
for (int i = 0; i < Textproperties.lenght();i++){
/*
*Textproperties[0] give maxlength of Text Box.
*Textproperties[1] give size of Text Box.
**/

}
selenium.type("q", "selenium");
selenium.stop();
}



}

Selenium UI Testing

Selenium UI Testing

Below are methods that can be used to test position of element in web page

UI Testing can be done using these method


1. getElementHeight(java.lang.String locator)
2. getElementPositionLeft(java.lang.String locator)
3. getElementPositionTop(java.lang.String locator)
4. getElementWidth(java.lang.String locator)

Selenium PDF Testing

I came across queries related to Testing PDF in web page . As after clicking on PDF link , PDF file on on same page , But we can not either verify Text or any content on that page.

So I thought of copying that data into text File and comparing data in that Text File with actuall Text File.

As we know that after pressing CTRL+A ,CTRL+C text are stored in clipboard. So we can move that data in Text File .

Example given below is performed on selenium forum site itself.


Below is Java code for that

TextClipBoard Class where actuall data from PDF is moved to text file .

package Selenium;


import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
import java.awt.event.KeyEvent;
import java.io.*;

public class TextClipBoard extends SeleneseTestCase {

public void setUp() throws Exception {
setUp("http://seleniumhq.org/", "*chrome");
}

public void testNew() throws Exception {

/*
* Opening Selenium Site
*/

selenium.open("/");

/*
* Clicking on link Forums
*/

selenium.click("link=forums");

/*
* Waiting for Elements presence because , while Testing page is getting timeout after
* default timeout period , So I searched for Communities keyword in that page
*/

for (int second = 0;; second++) {

if (second >= 60) fail("timeout");

try { if (selenium.isElementPresent("css=h4:contains(\"Communities\")")) break; }

catch (Exception e) {}

Thread.sleep(1000);
}

/*
* Clicking on recently posted link in forum site
*/

selenium.click("link=Clover report for Selenium tests");

/*
* Waiting for Default Timeout period
*/

selenium.waitForPageToLoad("30000");


/*
* Clicking on View as pdf link
*/

selenium.click("link=View as PDF");


/*
* Maximizing window and moving focus to that page
*/

selenium.windowMaximize();

selenium.windowFocus();

pause(10000);



selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL)); //Stands for CONTROL

pause(1000);

selenium.keyPressNative("65"); // Stands for A "ascii code for A"

pause(4000);

selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));//Stands for CONTROL

pause(1000);

selenium.keyPressNative("67"); // Stands for C "ascii code for C"

/*
* Below code is call to Text Transfer class so as to retrieve data from Clip Board
* As we know that after copying data using ctrl+A and ctrl+C data remain in clip board
* We can move that data into Text File
*/

TextTransfer textTransfer = new TextTransfer();

//display what is currently on the clipboard

System.out.println("Clipboard contains:" + textTransfer.getClipboardContents() );
pause(4000);

selenium.stop(); // Kill the Browser

/*
* Writing data into Text File so as to compare these data with actual data.
* */

Writer output = null;

String text = textTransfer.getClipboardContents();

File file = new File("D:\\write.txt");

output = new BufferedWriter(new FileWriter(file));

output.write(text);

output.close();

try{

FileInputStream fstream = new FileInputStream("D:\\write.txt");

// Get the object of DataInputStream

DataInputStream in = new DataInputStream(fstream);

BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strLine;

//Read File Line By Line

while ((strLine = br.readLine()) != null) {

// Print the content on the console

System.out.println ("Reading from File line by line : " +strLine);

}

//Close the input stream

in.close();

}
catch (Exception e){//Catch exception if any

System.err.println("Error: " + e.getMessage());

}
}



}


TextTransfer class to retrieve data from Clipboard



package Selenium;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.Toolkit;
import java.io.*;

public final class TextTransfer implements ClipboardOwner {

public static void main (String... aArguments ){
TextTransfer textTransfer = new TextTransfer();

//display what is currently on the clipboard
System.out.println("Clipboard contains:" + textTransfer.getClipboardContents() );

//change the contents and then re-display

textTransfer.setClipboardContents("blah, blah, blah");

System.out.println("Clipboard contains:" + textTransfer.getClipboardContents() );

}

/**
* Empty implementation of the ClipboardOwner interface.
*/
public void lostOwnership( Clipboard aClipboard, Transferable aContents) {
//do nothing
}

/**
* Place a String on the clipboard, and make this class the
* owner of the Clipboard's contents.
*/
public void setClipboardContents( String aString ){
StringSelection stringSelection = new StringSelection( aString );

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

clipboard.setContents( stringSelection, this );

}

/**
* Get the String residing on the clipboard.
*
* @return any text found on the Clipboard; if none found, return an
* empty String.
*/
public String getClipboardContents() {
String result = "";

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

//odd: the Object param of getContents is not currently used

Transferable contents = clipboard.getContents(null);

boolean hasTransferableText =

(contents != null) &&
contents.isDataFlavorSupported(DataFlavor.stringFlavor)
;
if ( hasTransferableText ) {

try {

result = (String)contents.getTransferData(DataFlavor.stringFlavor);

}

catch (UnsupportedFlavorException ex){

//highly unlikely since we are using a standard DataFlavor
System.out.println(ex);

ex.printStackTrace();

}
catch (IOException ex) {

System.out.println(ex);

ex.printStackTrace();

}

}

return result;
}
}

Selenium SSL Site Testing / Secure [HTTPS] Site Testing

Selenium SSL Site Testing / Secure [HTTPS] Site Testing


Selenium Secure Site [HTTPS] Testing



Below are steps that need to be followed to Test HTTPS – Secure Site :

Selenium uses its own Certificate for all https-connections, the Certificate is Cybervilian Certificate. We have to import the certificate into your Internet Explorer.

Please follow below steps to import Cybervilian Certificate.

1.Open Internet Explorer.
2.Navigate to Tool->Option.
3.Click on content Tab.


1.Now click on certificates button.


5.Click on Import button.

6.Click on Next > button.
7.Click on browse button.



8.Import cybervilliansCA .
9.Click on Next > button.
10.Again Click on Next > button.
11.Click on Finish button.
Image will be displayed as below on succesfull import of certificate.


12.Now open secure site:
Example: https://herald.cybage.com/exchange
13.Security Alert will be shown as below:


14. Click on View Certificate button.
15.Click on Install Certificate button .



16.Click on Next > button.

17.Click on Next > button.

18.Click on Finish button.
On Succesfull import of certificate

19.Click on yes button, After successful import of certificate .

20.Now you can run your Test Case.

First time while running HTTPS Test Case you may find alert box will be shown , click on OK and remember my decision .

Below example is used by be to Test my official Email Site, though password has been changed by me for confidential reason:

Below code is used to connect HTTPS site in Internet Explorer .


package Selenium;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

public class CertificateTest extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("https://herald.cybage.com/exchange", "*iexplore");
}
public void testSecureSite() throws Exception {
selenium.open("/exchweb/bin/auth/owalogon.asp?url=https://herald.cybage.com/exchange&reason=0");
selenium.type("username", "XXXXXX");
selenium.type("password", "XXXXXX");
selenium.click("SubmitCreds");
}
}























To run Test Case in Firefox . Please follow below steps:
1.Close all instance of Firefox .
2.Start Firefox from command prompt using command: firefox –ProfileManager


1.Create a new profile. You'll be prompted to choose a directory for the profile.
2.Select the profile and run Firefox using it.
3.Browse to the HTTPS URL (with self-signed certificate) you're going to be testing against.
4.Accept the self-signed certificate when prompted. This creates an exception for it in the profile.
5.Close the browser.
6.Go to the Firefox profile directory.
7.Delete everything in the directory except for the cert_override.txt and cert8.db files.
8.Start Selenium Server using below command:
When you run your Selenium server pass a
-firefoxProfileTemplate /path/to/profile/dir argument to it. This tells Selenium to use your partial profile (with certificate exceptions) as a basis for minting its new profile.














package Selenium;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

public class CertificateTest extends SeleneseTestCase {

public void setUp() throws Exception {
setUp("https://herald.cybage.com/exchange", "*firefox");
}

public void testSecureSite() throws Exception {
selenium.open("/exchweb/bin/auth/owalogon.asp?url=https://herald.cybage.com/exchange&reason=0");
selenium.type("username", "XXXXX");
selenium.type("password", "XXXXX");
selenium.click("SubmitCreds");
}