as

Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, 1 June 2015

How to get search queries for given keyword from Google by Automation

Here is the sample program to get the list of search queries related to given keyword.
package framework;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintStream;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public  class Google {
   
   
   public static void main(String[] args) {
   
         WebDriver driver =null;
         
   System.setProperty("webdriver.chrome.driver", "F:\\selenium\\chromedriver.exe");
   System.out.println(System.getProperty("webdriver.chrome.driver"));
   driver = new ChromeDriver();
   
  // driver = new ChromeDriver(DesiredCapabilities.chrome());      driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
   driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
   driver.manage().window().maximize();
   
   try{
      
driver.get("https://www.google.co.in/preferences?hl=en-IN&fg=1");  
driver.findElement(By.xpath("//div[text()='Never show Instant results.']")).click();
driver.findElement(By.xpath("//div[text()='Save']")).click();

driver.get("https://www.google.co.in");       

//String x = driver.switchTo().frame(0).switchTo().frame(0).findElement(By.tagName("h3")).getText();//String x = driver.switchTo().frame(1).findElement(By.tagName("h3")).getText();//String x = driver.switchTo().frame("view").switchTo().frame(0).getPageSource();//System.out.println(x);
String str = "windows 7 How to ";
String d = "";
   
for (int i=1 ;i<=26;i++)
   
{
   char x = (char) (64+i);
   
driver.findElement(By.cssSelector("input[name=q]")).sendKeys(str + x);

Thread.sleep(2000);
List <WebElement> tr =  driver.findElements(By.xpath("//table[@class='gssb_m']//tr"));

for (int co=0 ; co<tr.size();co=co+2)
{
   
   d= d + tr.get(co).getText() + "\r\n";
}

driver.findElement(By.id("lst-ib")).clear();

}

System.out.println(d);
String filePath = "f:\\videos\\"+ str +".txt";
               
               if ((new File(filePath)).exists() )
                  (new File(filePath)).delete();
               
               
               File temp = new File(filePath);
               FileWriter fw = new FileWriter(temp,true);
               fw.append(d);
               fw.close();
               


 

            Thread.sleep(4000);
            //driver.navigate();//driver.navigate("http://www.google.com");      }catch(Exception e){

   //System.out.println(e.getLocalizedMessage());                  e.printStackTrace(new PrintStream(System.out));
         
      }
         
         
      finally{
         driver.close();
         driver.quit();
      }  
         
      
      
      
      
   }
   
   

   
}


What do you think on this topic? Please express your opinion or ask any question through comment below. You can write to me at reply2sagar@gmail.com

Friday, 15 August 2014

Android classes in Pimpri Chinchwad and Pune

We provide Android classes in Pimpri Chinchwad and Pune. Details are given below.

What is Android and why you should learn Android?

Android is a popular mobile operating system and there is huge demand for Android developers.

The features of Android are given below.

  1. Open source.
  2. Developed in Java.


What Is The Syllabus Of Android Course?

Syllabus for the Android Course is given below.

  1. Installation of Android Studio in windows.
  2. GUI of Android Studio.
  3. First Android App.
  4. Building and running Application on AVD and actual mobile phones.
  5. Debugging Android applications.
  6. Generating apk files for distributions.
  7. Activities, Services, Broadcast receivers.
  8. View and View Groups, Fragments.
  9. Layout files.
  10. Manifest Files and permissions.
  11. Android App with multiple activities.
  12. Working with buttons, check boxes, Spinners, Auto complete text boxes, Text view, edit boxes.
  13. Handling click events and key press events.
  14. Working with Telephone manager.
  15. Sending SMS, mails.
  16. Text to speech conversion Application.
  17. Sqlite and Android.
  18. Simple calculator application using Android.
  19. GPS tracking using Android.
  20. Simple Database application using Android.

Duration And Timing Of The Android Course.

Duration for Android course will be 2 months. Classes will be conducted over weekend on Saturday and Sunday. Each class will be of 1 hour each.

Fee Of The Android Course
Fee for the Android  course will be 10k if paid upfront. It will be 12k if paid in 2 installments.

How to register for the Android course/ Class
You can reach me by any of the ways mentioned below.

Gmail         Reply2sagar@Gmail.Com
Skype         Revert2sagar
Facebook         Https://Www.Facebook.Com/Sagar.Salunke.186
What's app +919850182384

Location Of The Android Course
Android  classes are conducted at fortitude systems, near gurudwara, Akurdi Station.

What do you think on this topic? Please express your opinion through comment below. You can write to me at reply2sagar@gmail.com

Friday, 6 September 2013

How to automate test cases using selenium in JAVA?

In this article I will tell you how we can do web automation using selenium in JAVA.

What you need to start with...
You will need to download below software to start automation

  1. Selenium API - https://code.google.com/p/selenium/downloads/list
  2. Webdriver for Interenet Explorer - https://code.google.com/p/selenium/downloads/list
  3. Webdriver for Chrome - https://code.google.com/p/chromedriver/downloads/list
  4. Eclipse  - Java IDE
Once you have these softwares with you, You can follow below steps.
  1. Open Eclipse and create new Java Project.
  2. Create a package and class with name SampleTest in it.
  3. Go to project properties and select Java build path. Select libraries tab and then choose add external jar.
  4. Browse to the jar file you have downloaded in step 1 first list.
  5. Select apply and close
Source code of SampleTest.java is given below.



package seleniumpackage;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

//import com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutor;
//import org.openqa.selenium.firefox.*;

@SuppressWarnings("unused")
public class SampleTest {
    
public static void main(String [] arg) 
{
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver =  new ChromeDriver();

        // System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer.exe");
//wd =  new InternetExplorerDriver();
try{
//Install selenium 2.0 -> https://code.google.com/p/selenium/downloads/list
//Install chromedriver -> https://code.google.com/p/chromedriver/downloads/list
//Install IEDriver     -> https://code.google.com/p/selenium/downloads/list
//Get Eclipse          -> Java IDE

//***********************************************************************
// List of common operations on web elements
//***********************************************************************
//We will see lot of operation that can be done in selenium 
//1.Clicking on the WebElement.
//2.Enter value in editbox WebElement.
//3.Select value from the dropdown WebElement.
//4.Select radiobutton WebElement.
//5.Select the checkbox WebElement.
//6.Clicking/accessing hidden WebElements. -> Make them visible first and then click
//7.How to check if element exists in page.
//8.reading data from table rows, cells etc.
//9.Different ways of accessing elements.
//10.Synchronization methods in selenium in Java.
driver.navigate().to("http://www.google.com");
Thread.sleep(5000);
/* Check if element is present or Not */
Boolean isPresent = driver.findElements(By.id("lst-ib")).size()<0;
System.out.println("Element is present  " + isPresent );
/*Check if element is displayed in selenium */
System.out.println ( "Element with id visible -> " + driver.findElement(By.id("gb_51")).isDisplayed());
System.out.println ( "Element with id visible -> " + driver.findElement(By.name("q")).isDisplayed());
/*click on the webelelment */
driver.findElement(By.linkText("News")).click();
/*enter value in the edit box */
driver.findElement(By.name("q")).sendKeys("Selenium");
 
      /*Select value from drop down*/
//Select select=new Select(driver.findElement(By.id("abc")));
       //select.selectByVisibleText("=");   
/* Peforming mouseOver Event on the WebElement*/
//Actions builder = new Actions(driver);
                //Action hoverAction = builder.moveToElement(WE).build();
                //hoverAction.perform();
/*Accessing data from webtable */
/*
WebElement r =  wd.findElement(By.xpath("//*[@id='acd']/table/thead/tr"));
List<WebElement> cells = r.findElements(By.tagName("th"));
        int c = 0;
    for (WebElement cell : cells) {
       c=c+1;
       System.out.println(c + " --> "+ cell.getText() );
    if (head.equals(cell.getText()))
    break;
    }
    */
/*Wait until Element is present */
//WebElement me = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("myid")));
/*Wait until Element is clickable */
//WebDriverWait wait = new WebDriverWait(driver, 10);
//me = wait.until(ExpectedConditions.elementToBeClickable(By.id("myid")));
/*Implicit waits */
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
/* Locating elements */
//WebElement frame = driver.findElement(By.tagName("iframe"));
//List<WebElement> cheeses = driver.findElements(By.className("cheese"));
//WebElement cheese = driver.findElement(By.name("cheese"));
//WebElement element = driver.findElement(By.id("coolestWidgetEvah"));
//WebElement cheese = driver.findElement(By.linkText("cheese"));
//WebElement cheese = driver.findElement(By.partialLinkText("cheese"));
//WebElement cheese = driver.findElement(By.cssSelector("#food span.dairy.aged"));
//List<WebElement> inputs = driver.findElements(By.xpath("//input"));
/*We can also execute java script*/ 
//WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("return $('.cheese')[0]");
//List<WebElement> inputs = (List<WebElement>) ((JavascriptExecutor)driver).executeScript(
//    "var labels = arguments[0], inputs = []; for (var i=0; i < labels.length; i++){" +
 //  "inputs.push(document.getElementById(labels[i].getAttribute('for'))); } return inputs;", labels);
/* Getting all options in drop down */
/*
WebElement select = driver.findElement(By.tagName("select"));
List<WebElement> allOptions = select.findElements(By.tagName("option"));
for (WebElement option : allOptions) {
   System.out.println(String.format("Value is: %s", option.getAttribute("value")));
   option.click();
}
*/
/* Selecting from dropdown
 
Select select = new Select(driver.findElement(By.tagName("select")));
select.deselectAll();
select.selectByVisibleText("Edam");
*/
//Alert alert = driver.switchTo().alert();
//driver.navigate().forward();
//driver.navigate().back();
//driver.get("www.google.com");
 //***************************************************************
// List of common Exception while working with WebElements
//*********************************************************************
//1."Element is not clickable at point (x, y). 
//2.No Such Element - for Frame related issue
//3.The driver executable does not exist
//4.Driver executable must be set by the webdriver.ie.driver system property
//5.The path to the driver executable must be set by the webdriver.chrome.driver system property
}
catch(Exception e){
System.out.println("Exception - > " + e.toString());
}
finally{
driver.close();
driver.quit();
}
    
}
}




This is how we can automate any web browser using selenium



What do you think on this topic? Please express your opinion through comment below

Tuesday, 2 July 2013

Application blocked by security settings while running applet from browser

Your security settings have blocked the application from running.




Have you faced this error while trying to run java applet from any of the browser like chrome, internet explorer or Mozilla firefox?
If yes, you can fix this problem by following below steps.

In Windows xp or windows 7 you can go to java settings through control panel.
Then you have to select the security tab.
Then set the security level to medium. Then you have to restart the browser and check if applet is working or not.
Please ensure that you have enabled the Java plug-in in the browser.






In newer Java version 1.7 and above, You will not see security level as medium. Below screenshot shows the security tab for latest java environment.


So if you want to run applet in browsers, you will have to add the url to the exception list.
Another thing is that you should also make sure that Java plug-in of your browser is enabled.

You may also encounter exception - ClassNotFoundException. This error comes when your class is not in the classpath. Applet searches the classes in current directory. If it does not find the the classes in the current directory, it searches the class in directories mentioned in classpath environment variable. If it is not found there as well, ClassNotFoundException is thrown.


What do you think on this topic? Please express your opinion through comment below

Friday, 28 June 2013

What are the different syllabus/course topics in JAVA?

Java is a huge language. When you join Java course, you must ask the questions - What topics will be covered. I have divided JAVA courses in below Parts. This might help you in determining what you want to learn.

Different JAVA Course and Topics Covered in it.
  1. Basic/Core Java      - Data types, Variables, Modifiers, Control Statements, Arrays, Strings, Regular Expression, Files, Exceptions, Interfaces, OOP Concepts, Data Structures, Collections, Multi-threading, Applets, JDBC, Networking, Email, Serialization, Layout Manager, Swing 
  2. Advanced Java        - Tomcat, Weblogic, Jsp, Servlets, JSON,  Rest, Hibernate, Jasper Reports, Generics.
  3. Java Frameworks    - Spring, Struts.
  4. Java Tools                -  maven, Apache ant, iBATIS, log4j.
  5. Java IDEs                 -  Eclipse, NetBeans, JCreator, IntelliJ IDEA, BlueJ, MyEclispe
  6. Java Testing Frameworks - Junit, TestNG
So if you are new to JAVA, I will recommend that you should first learn topics in Basic Java Course and then you can go for advanced course and in the end you must learn frameworks like spring and struts.

What do you think on this topic? Please express your opinion through comment below

What are the steps to install Struts in Windows?


Well - Struts is a java based web application framework used to develop RIA - Rich Internet Applications.
Below are the steps to install and start developing the web application in JAVA.



Once you 4 things mentioned above you can start web application development in JAVA.
Ensure that you have your java variables set up properly before you work on struts framework


What do you think on this topic? Please express your opinion through comment below

What are different System Variables in JAVA?

When working with JAVA, You need to set up/edit  below variables in Windows System.
  • PATH - You need to edit this variable after you install JAVA in windows system. It should contain the value like this C:\jdk1.5.0_20\bin;%PATH% 
  • JAVA_HOME: This variable should be set like C:\jdk1.5.0_20
  • CLASSPATH - This variable contains the paths to folders where JVM must search for classes. For example C:\struts-2.2.3\lib
  • CATALINA_HOME - This variable contains the path to your tomcat container. For example -C:\apache-tomcat-6.0.33 . This is required if you are developing the web based application using jsp and servlet in JAVA
If you think that I have missed any other system environment variables in windows for Java, You can comment below.



What do you think on this topic? Please express your opinion through comment below

Thursday, 27 June 2013

What are the Categories of Exceptions in JAVA

There are 3 categories of Exceptions in JAVA.



  • Checked exceptions:  These exceptions can be found at the time of compilation. For example class not found, method not found


  • Runtime (Unchecked) exceptions: A runtime exception is an exception that can be ignored at the time of compilation. For example - array index out of bound, divide by zero error.


  • Errors: Can not be found at the time of compilation. Here Programmer has no control over these kinds of exceptions. For example JVM running out of memory.


If a method does not handle a checked exception using try catch blocks, the method must declare it using the throws keyword. 

Here is the syntax of Method that throws exception.

public void dosomething(int a ) throws  IOException
 {

 // Method code

 throw new IOException();

 }


Finally block is used along with try catch blocks. Code in finally block is executed regardless of whether exception occurs or not.







Sponsored Links

Popular Posts

Comments

ShareThis