Press escape key : Send("{ESCAPE}")
Press enter key : Send("{ENTER}")
Press tab key : Send("{TAB}")
Enter some content and press tab key : Send("water{TAB}")
Enter some content and press enter key : Send("water{ENTER}")
Tuesday, January 17, 2012
Autoit for File upload
Firefox
WinWaitActive("File Upload")
if WinExists("File Upload") Then
ControlSetText("File Upload", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("File Upload", "", "Button2")
EndIf
IE
WinWaitActive("Choose file")
if WinExists("Choose file") Then
ControlSetText("Choose file", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("Choose file" ,"", "Button2")
EndIf
Chrome
WinWaitActive("Open")
if WinExists("Open") Then
ControlSetText("Open", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(2000)
ControlClick("Open", "", "Button2")
EndIf
For more reference follow these links. These guys have given nice example
http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html
http://automationtricks.blogspot.com/2010/09/how-to-upload-file-in-selenium-with.html
http://iautomateit.wordpress.com/2011/07/15/working-around-file-upload-dialog-issues-with-selenium-2/
http://bharath-marrivada.blogspot.com/2011/02/selenium-autoitv3-file-upload-download.html
WinWaitActive("File Upload")
if WinExists("File Upload") Then
ControlSetText("File Upload", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("File Upload", "", "Button2")
EndIf
IE
WinWaitActive("Choose file")
if WinExists("Choose file") Then
ControlSetText("Choose file", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(1000)
ControlClick("Choose file" ,"", "Button2")
EndIf
Chrome
WinWaitActive("Open")
if WinExists("Open") Then
ControlSetText("Open", "", "Edit1", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg")
Sleep(2000)
ControlClick("Open", "", "Button2")
EndIf
For more reference follow these links. These guys have given nice example
http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html
http://automationtricks.blogspot.com/2010/09/how-to-upload-file-in-selenium-with.html
http://iautomateit.wordpress.com/2011/07/15/working-around-file-upload-dialog-issues-with-selenium-2/
http://bharath-marrivada.blogspot.com/2011/02/selenium-autoitv3-file-upload-download.html
Thursday, January 12, 2012
FirefoxDriver with custom profile
Use profile manager to create profiles. In Windows machine profiles will be stored in the path
FirefoxProfile profile = new ProfilesIni().getProfile("profileName");
FirefoxDriver driver = new FirefoxDriver(profile);
Once firefox window opens check that addon's, bookmark etc are appearing in the newly opened firefox window.
C:\Documents and Settings\user\Application Data\Mozilla\Firefox\Profiles\
FirefoxProfile profile = new ProfilesIni().getProfile("profileName");
FirefoxDriver driver = new FirefoxDriver(profile);
Once firefox window opens check that addon's, bookmark etc are appearing in the newly opened firefox window.
Simulate click using javascript for webdriver
driver.get("http://www.google.com");
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement upload = driver.findElement(By.name("btnI"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", upload);
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement upload = driver.findElement(By.name("btnI"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", upload);
By pass certificate validation failure in IE for https pages
if (driver instanceof InternetExplorerDriver)
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
Wednesday, January 4, 2012
ISuiteListener and ITestListener
Sample usage
public class TestReporter implements ITestListener {
static int count;
public void onFinish(ITestContext arg0) {
System.out.println("Test Finished !!!!!!!!");
}
public void onStart(ITestContext arg0) {
ISuite suite = arg0.getSuite();
System.out.println("Driver is : ");
ITestNGMethod[] value = arg0.getAllTestMethods();
System.out.println("Method Number : "+value.length);
count = value.length;
}
@Override
public void onTestFailure(ITestResult arg0) {
// System.out.println("Finished Executing Test: "+arg0.getName()+" Status: Failed"+"\n Reason:"+arg0.getThrowable());
}
@Override
public void onTestSkipped(ITestResult arg0) {
// System.out.println("Skipped test: "+arg0.getName()+".Reason"+arg0.getThrowable());
}
@Override
public void onTestStart(ITestResult arg0) {
// System.out.println("Starting Test: "+arg0.getName());
// System.out.println("\n Starting Test: "+count--);
}
@Override
public void onTestSuccess(ITestResult arg0) {
System.out.println("Finished Executing Test: "+arg0.getName()+" Status: Success.");
System.out.println("Class Name : "+arg0.getTestClass());
Object[] ab = arg0.getParameters();
System.out.println("Param Set : "+ab.length);
for(int i = 0 ; i < ab.length ; i++)
System.out.print(ab[i]+" ");
// System.out.println("Method Name : "+arg0.getMethod().getMethodName());
}
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
// System.out.println("Test failed but within success percentage");
}
}
public class SuiteReporter implements ISuiteListener {
@Override
public void onFinish(ISuite arg0) {
System.out.println("Finished executing the suite");
System.out.println("********Results*******");
}
@Override
public void onStart(ISuite arg0) {
System.out.println("Starting Execution");
//Print suiteName
System.out.println("Suite Name:"+arg0.getName());
//Print HostName
// System.out.println("Host Name:"+arg0.getHost());
//Returns null if it runs locally
}
}
<suite name="Sample Suite">
<!--
<listeners>
<listener class-name="com.clearspring.qa.tellurium.SuiteReporter" />
<listener class-name="com.clearspring.qa.tellurium.TestReporter" />
</listeners>
<test>
</test>
</suite>
public class TestReporter implements ITestListener {
static int count;
public void onFinish(ITestContext arg0) {
System.out.println("Test Finished !!!!!!!!");
}
public void onStart(ITestContext arg0) {
ISuite suite = arg0.getSuite();
System.out.println("Driver is : ");
ITestNGMethod[] value = arg0.getAllTestMethods();
System.out.println("Method Number : "+value.length);
count = value.length;
}
@Override
public void onTestFailure(ITestResult arg0) {
// System.out.println("Finished Executing Test: "+arg0.getName()+" Status: Failed"+"\n Reason:"+arg0.getThrowable());
}
@Override
public void onTestSkipped(ITestResult arg0) {
// System.out.println("Skipped test: "+arg0.getName()+".Reason"+arg0.getThrowable());
}
@Override
public void onTestStart(ITestResult arg0) {
// System.out.println("Starting Test: "+arg0.getName());
// System.out.println("\n Starting Test: "+count--);
}
@Override
public void onTestSuccess(ITestResult arg0) {
System.out.println("Finished Executing Test: "+arg0.getName()+" Status: Success.");
System.out.println("Class Name : "+arg0.getTestClass());
Object[] ab = arg0.getParameters();
System.out.println("Param Set : "+ab.length);
for(int i = 0 ; i < ab.length ; i++)
System.out.print(ab[i]+" ");
// System.out.println("Method Name : "+arg0.getMethod().getMethodName());
}
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
// System.out.println("Test failed but within success percentage");
}
}
public class SuiteReporter implements ISuiteListener {
@Override
public void onFinish(ISuite arg0) {
System.out.println("Finished executing the suite");
System.out.println("********Results*******");
}
@Override
public void onStart(ISuite arg0) {
System.out.println("Starting Execution");
//Print suiteName
System.out.println("Suite Name:"+arg0.getName());
//Print HostName
// System.out.println("Host Name:"+arg0.getHost());
//Returns null if it runs locally
}
}
<suite name="Sample Suite">
<!--
<listeners>
<listener class-name="com.clearspring.qa.tellurium.SuiteReporter" />
<listener class-name="com.clearspring.qa.tellurium.TestReporter" />
</listeners>
<test>
</test>
</suite>
Subscribe to:
Posts (Atom)