Tuesday, 28 January 2014

Compose a mail with Attached file using Auto it tool.

package googlechrome;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class gmail {

private Process process;
@Test
public  void run() throws Exception{
System.setProperty("webdriver.chrome.driver","C:\\Users\\gwda\\Desktop\\chromedriver.exe");
WebDriver s1 = new ChromeDriver();
s1.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
s1.get("http://www.gmail.com");
s1.findElement(By.xpath("//input[@id='Email']")).sendKeys("mail id");
s1.findElement(By.xpath("//input[@id='Passwd']")).sendKeys("password");
s1.findElement(By.xpath("//input[@id='signIn']")).click();
s1.findElement(By.xpath("//div[@class='T-I J-J5-Ji T-I-KE L3']")).click();
Thread.sleep(3000);
        s1.findElement(By.xpath("//textarea[@class='vO']")).sendKeys("ngowda.unilog@gmail.com");

s1.findElement(By.xpath("//input[@name='subjectbox']")).sendKeys("hi");
s1.findElement(By.xpath("//div[@class='Am Al editable LW-avf']")).sendKeys("dear friend," +
" " +
"welcome to send a mail using seenium" +
"using the Auto it for Ataching the File " +
"in Gmail ID will be dynamicaly changing so we have to use only which one static," +
"here i am using the CLASS some where it s also changing, where it s changing we have use another." +
" Regards" +
" NGOWDA" +);

s1.findElement(By.xpath("//div[@class='a1 aaA aMZ']")).click();//sendKeys("supply");
//it is a Auto it code for uploading a file. please use Auto it for upload a file.
process = new ProcessBuilder("C:\\Users\\gwda\\Desktop\\file1.exe",
        "C:\\Users\\gwda\\Desktop\\PartListLoader.txt","Open").start();
Thread.sleep(30000);
s1.findElement(By.xpath("//div[contains(text(),'Send')]")).click();
Thread.sleep(3000);
s1.findElement(By.xpath("//div[@class='a1 aaA aMZ']")).click();
s1.close();
}

}

Monday, 27 January 2014

Uploading the File in E-commerce site using Auto-it tool.

package Test;

import java.io.File;
import java.io.IOException;
import java.sql.Time;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.testng.annotations.Test;
import org.testng.annotations.Test;

public class File upload {


private Process process;

@Test
public void run() throws IOException, InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\gwda\\Desktop\\chromedriver.exe");
WebDriver s1 = new ChromeDriver();
s1.get("Enter your URL");
s1.manage().window().maximize();
s1.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS );
s1.findElement(By.id("mainUserName")).sendKeys("username");
s1.findElement(By.id("mainPassword")).sendKeys("password");
s1.findElement(By.xpath("//input[@src='images/ButtonSignIn.png']")).click();
        Thread.sleep(3000);
     
   
       
 s1.findElement(By.xpath("//ul[1]/li[3]/a[contains(text(),'File Upload')]")).click();
        s1.findElement(By.xpath("//input[@id='uploadfile']")).click();

        process = new ProcessBuilder("C:\\Users\\gwda\\Desktop\\file1.exe",
        "C:\\Users\\gwda\\Desktop\\PartListLoader.txt","Open").start();  
        Thread.sleep(3000);
        s1.findElement(By.xpath("//input[@id='fileRead_fileTypeTab Delimited Text File(.txt)   ']")).click();
        Thread.sleep(3000);
        s1.findElement(By.xpath("//span[@id='loadList']")).click();
        Thread.sleep(3000);
        s1.findElement(By.xpath("//span[contains(text(),'Yes')]")).click();
        Thread.sleep(3000);
     
        File scrFile3 = ((TakesScreenshot)s1).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile3, new File("c:\\tmp\\k1.png"));
}

}