Monday, 30 April 2018

Java Tutorial From Basics

Step By Step Learning of JAVA : 


Java History : 


Java was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language.  Writing, compiling and debugging a program is easy in java.  It helps to create modular programs and reusable code. 


Java is an Object Oriented language


Object oriented programming is a way of organizing programs as collection of objects, each of which represents an instance of a class.
4 main concepts of Object Oriented programming are:
  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism

Run First Java Program: Here


You can Mail is you face any issues.
Mail: rajan.sethi36@gmail.com
Thanks.



Run your First Java Program


How to Compile and Run your First Java Program


Simple Java Program:


Create a java project in IDE. Create package in src and java class in that package.

public class demoFirstProgram {
  public static void main(String[] args){
    System.out.println("This is my first program in java");
  }//End of main
}

Explanation of the Code:


public static void main(String[] args)  {
This is our next line in the program, lets break it down to understand it: public: This makes the main method public that means that we can call the method from outside the class.
static: We do not need to create object for static methods to run. They can run itself.
void: It does not return anything.
main: It is the method name. This is the entry point method from which the JVM can run your program.
(String[] args): Used for command line arguments that are passed as strings.
System.out.println("This is my first program in java");
This method prints the contents inside the double quotes into the console and inserts a newline after.
You can Mail is you face any issues.
Mail: rajan.sethi36@gmail.com
Thanks.

Tuesday, 9 August 2016

Cucumber Selenium Integration


CUCUMBER AND SELENIUM INTEGRATION


WHY CUCUMBER?


Many testers feel that there is no need of cucumber it is a waste,it is doing something that they already do with the existing tool according to them there is no use to add natural language to you project or code.What matters is the CODE

Now there is answer of WHY?

Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. Tests are written in plain language based on the behavior-driven development (BDD) style of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.This English(or other natural language)feature files serve as the abstraction over code that allows those statements to execute.Cucumber interprets the tests into the specified programming language and uses Selenium to drive the test cases in a browser. Our tests are translated into Java code.

ADVANTAGES OF SELENIUM WITH CUCUMBER

The advantages of using Selenium with Cucumber for automated testing. Using this framework, you write tests in feature files in a form understandable by any business manager or other non-technical stakeholder. The tests are then translated into the Java language by Cucumber, which supports multiple scripting and programming languages. Selenium is used to drive the browser.

Prerequisites: 

  • Eclipse IDE
  • Jar files required by the framework
    • mockito-core-2.0.8.jar
    • cucumber-4.12.jar
    • gherkin-2.12.2.jar
    • reporting-0.1.0.jar
    • cucumber-jvm-.deps-1.0.3.jar
    • cucumber-junit-1.2.2.jar
    • cucumber-java-1.2.2.jar
    • cucumber-core-1.2.2.jar
    • cobertura-2.1.1.jar
    • cucumber-HTML-0.2.3-sources.jars
    • Selenium-Server-standalone


Steps to make cucumber framework

1.Create a new Java project.





2.Configure Build Path (add all the jars mentioned above)



3.In project make a folder "features" and in that make a feature file "myapplication.feature".




      3.1. Feature in my case is :



4.Now in src, make a package called runner and in this package make a class called TestRunner.


   
 4.1 TestRunner in my case is:


 

5.Now run the TestRunner using JUnit.

6.Now you can see that console display a message that you should make this functions...



7.Create a new package in src called stepdefination and in package create a class called testdefinations.


           7.1 testdefination class in my case is : 

package stepdefination;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class testdefinations {

WebDriver driver;

@Given("^Open Chrome$")
public void open_Chrome() throws Throwable {
   
System.setProperty("webdriver.chrome.driver", "\\path\\to\\chrome\\setup\\");
driver= new ChromeDriver();
driver.manage().window().maximize();
  //throw new PendingException();
}

@Given("^Start application$")
public void start_application() throws Throwable {
driver.get("https://www.facebook.com/");
   // throw new PendingException();
}

@When("^I enter valid username$")
public void i_enter_valid_username() throws Throwable {
    
driver.findElement(By.id("******")).sendKeys("username");
    //throw new PendingException();
}

@When("^valid passpord$")
public void valid_passpord() throws Throwable {
driver.findElement(By.id("******")).sendKeys("password");
driver.findElement(By.id("******")).click();
    
    //throw new PendingException();
}

@Then("^user should be able to login successfully$")
public void user_should_be_able_to_login_successfully() throws Throwable {
   
System.out.println("Able to LogIn");
    //throw new PendingException();
}

}


8.Update your TestRunner Class.




9.Run your TestRunner Class as JUnit.

10. Now you can see your HTML results in the folder target/cucumber made dynamically.


Happy Testing :)




Keywords Cucumber, Selenium, Integration, Java, BDD, HTML, Eclipse.

Sunday, 12 June 2016

How to Extract .App file from .ipa file & Install .App file to the IOS Simulator.

Keywords :  Xcode, IOS Simularors, SDKs, Appium, .App File, .ipa File, Mac OS X.

1. How to Extract .app file from .ipa file.


During Testing i faced some problems like "how can i install my .ipa file in the simulator" then after some research i got to know that if you want to install an App then you first have to convert or Extract your app file from your ipa file.


Follow these steps to achieve results : 

1. Download the app you want to store in your simulator from App store. 

2. Convert the Extension of the file from .ipa to .zip.

3. Extract all the contents of the .zip file. 

4. After extraction you will get Payload folder in which you can find your .app file and its Info.plist      file.

2. Install .App file to the IOS Simulator.


Now if you want to install the app in the simulator then you have to follow these simple steps to get the desired results.

1. Launch Xcode. 

2.Go to Xcode > Open Developer Options > IOS Simulator.

3. See all the apps in the simulator . 

4. Go to terminal and write " open  /Applications/Xcode/Contents/Developer/Platforms /iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Applications.

5.In this window you can see all the applications that are installed in the simulator.

6. Paste your .app file here and exit.

7. Relaunch your IOS Simulator . 

8. You can see you app in the Simulator. 




********************Looking for your Feedbacks*************************

*******************Enjoy Coding, Enjoy Automation********************** 



Related :  How to Run safari on real device

Wednesday, 1 June 2016

Sample code to Run a APP on Real Device through Appium

Sample code to Run a APP on Real Device through Appium.



This Piece of code tested on -
  • Appium -1.3.4 IOS -6 (8.1)
  •  Mac: Mavericks [10.9.5] 
  • Java -1.7 & 8 
  • TestNG 
  • WebDriver- 2.45

1. Install all the pre-requisites as mentioned above

2. Connect your Iphone and collect your udid through itunes.

3 Turn on the Appium server, you can do it in two ways :
  • Using Appium UI.
  • Through Terminal.
4 In my case, i am using terminal. Enter "appium -U xxxxxxxxxxxxxxxxxxxxxxxxx  --app /path/to/app/" command in your terminal. This will set the server on.
     
       xxxxxxxxxxxxxxxxxxxxxxx : Stands for UDID of your Device 

Note : you can add more arguments in the command like --address 127.0.0.1 and --port 4723.
           if you face any error.

5. Now you are all set to run your code.

6. Code : Java code written in Eclipse.


package runapp;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;


public class testapp {
 WebDriver wd;

 @BeforeTest
 public void beforeTest() throws MalformedURLException { 
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability("deviceName", "iPhone 6");
  capabilities.setCapability("platformName", "iOS");
  capabilities.setCapability("platformVersion", "8.1");
  capabilities.setCapability("app", "/path/to/app/");  //Path of Safari.app 
  capabilities.setCapability("udid", "xxxxxxxxxxxxxxxxxxx");

  wd = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  wd.manage().timeouts().implicitlyWait( 10,TimeUnit.SECONDS);
 }

 @Test
 public void clickonapp() throws InterruptedException {

wd.findElement(By.id("Login")).click();
  
 }

 @AfterTest
 public void afterTest() {
  wd.close();
 } 
}   



7.Run this code.

8.Check Terminal window, wheather system is pushing some commands or not .


Looking for your feedback. All The Best.


**************************Enjoy Automation****************************