Posted in Automation Testing Tool, chrome, Selenium

Automate and Test your Web page in Chrome emulator and Chrome View point using selenium and Java.

Now a days most of the application/url having compatibility to open in responsive or in emulator,So lot of people worried how to open these url in chrome emulator or view point using Selenium and java.

So here is the solution,Please go through this code and verify your site in chrome emulator or in View point.

Prerequisite:

You should have Java8, Selenium 3.14 + Jar in your system.I already mentioned in previous blog how to set browser path.Link

Example 1.

To open Url in chrome Nexus emulator:

Here i am using Google page to open in chrome Iphone Emulator

package testEmulatorOnChrome;
/*
* prerequisite to run this code you need
* Java 8, Selenium 3.14 +, and chrome driver
* To download all these you can visit
*/

import java.util.HashMap;
import java.util.Map;

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

public class TestEmulatorChrome {
public static void main(String[] args) {
Map<String, String> mobileEmulation = new HashMap<>();

mobileEmulation.put(“deviceName”, “iPhone 5”); //You can use various device like iPad,iPhone,Nexus etc.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption(“mobileEmulation”, mobileEmulation);
System.setProperty(“webdriver.chrome.driver”,”D:\\Software\\chromedriver.exe”);
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get(“https://www.google.com&#8221;);
driver.findElement(By.name(“q”)).sendKeys(“globallogic”);
driver.findElement(By.xpath(“//*[@id=\”tsf\”]/div[2]/div[1]/div[1]/button[2]”)).click();

}
}

Example 2:

To open Url in chrome View Point:

package testEmulatorOnChrome;
/*
* prerequisite to run this code you need
* Java 8, Selenium 3.14 +, and chrome driver
* To download all these you can visit
*/

import java.util.HashMap;
import java.util.Map;

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

public class TestMultibrowser2 {
public static void main(String[] args) {

Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put(“width”, 360);
deviceMetrics.put(“height”, 640);
deviceMetrics.put(“pixelRatio”, 4.0);

Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put(“deviceMetrics”, deviceMetrics);
ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setExperimentalOption(“mobileEmulation”, mobileEmulation);
System.setProperty(“webdriver.chrome.driver”,”D:\\Software\\chromedriver.exe”);
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get(“https://www.google.com&#8221;);
driver.findElement(By.name(“q”)).sendKeys(“globallogic”);
driver.findElement(By.name(“btnK”)).submit();

}
}

In case you find difficulty please let me know,

 

Here are some list of device you can use in this code..

Thanks, Keep learning New things….

Abhishek

Posted in Automation Testing Tool, Selenium

JUnit 4 vs JUnit 5:An Overview

Junit5

JUnit5, the Next Generation Junit. A Regression Testing Framework used by developers and tester to implement unit and functional testing in Java and Selenium, to accelerate programming speed and increase the quality of code. JUnit Framework can be easily integrated with either of the following –Eclipse, Ant, Maven. Junit5 introduces New Assert and Annotations to test your code more efficiently.

Junit5 requires Java 8 and above Java version and some useful annotations are:

@ParameterizedTest: Denotes that a method is a parameterized test. Such methods are inherited unless they are overridden.

 

@RepeatedTest: Denotes that a method is a test template for a repeated test. Such methods are inherited unless they are overridden.

@DisplayName: Declares a custom display name for the test class or test method. Such annotations are not inherited.

@BeforeEach: Denotes that the annotated method should be execute before each @Test,@RepeatedTest, @ParameteizedTest or @Test Factory method in the current class; analogous to JUnit 4’s @Before. Such methods are inherited unless they are overridden.

@AfterEach: Denotes that the annotated method should be executed after  @Test

@AfterAll:Denotes that the annotated method should be executed after @RepeatedTest@ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @AfterClass. Such methods are inherited (unless they are hidden or overridden) and must be static (unless the “per-class” test instance lifecycle is used).

@Tag: Used to declare tags for filtering tests, either at the class or method level; analogous to test groups in TestNG or Categories in JUnit 4. Such annotations are inherited at the class level but not at the method level.

Screen Shot 2018-08-07 at 4.12.22 PM

Asserts in Junit:

Screen Shot 2018-08-07 at 4.13.42 PM

For More Information you may visit JUnit Official site Click here and For comparison with JUnit 4 you may visit click here

Reference:https://junit.org/junit5/docs/current/user-guide/

Posted in Automation Testing Tool

Katalon Studio:An open source Automation tool

Katalon Studio is a comprehensive toolset for web and mobile app automation testing. This tool includes powerful features that help overcome common challenges in web UI test automation, for example, window popup, frames, wait, dropdown and many more inbuilt functions. This is user-friendly and help tester in automation to create regression suit better and faster even without prior knowledge of Scripting.

The tool is open source and can be downloaded at https://www.katalon.com.

Feature:

Katalon Studio is open source framework which comes with some advanced inbuild feature, Some of advanced feature are:

  • Support Web and mobile testing
  • Integrated with Restful and soup web services
  • You can pull test cases from JIRA
  • Inbuilt GIT repository support
  • Data management is very easy it support excel, database data,csv data and internal data.
  • Record and play funtionality
  • Even without prior knowledge of script you can create test cases.
  • User friendly
  • Suports groovy
  • Inbuilt functions

 Setup Katalon Studio in mac:

1.Redirected to https://www.katalon.com

2.Sign up for katalon studio

3.Download the .dmg file for mac

4.Install the package in Application folder

5.Open katalon studio enter userid and password and create a new project

6.Create new test case.

7.Record the test steps by clicking web recording button,after clicking the recording button a pop up will open(You can write the test script in groovy too)

8.Provide the test url and select the desired browser and click in browser icon.

9.After performing steps click on ok button

10.you will find test steps in created test case file

11.Execute the test case after selecting browser.

Note:You can insert assert or condition statement by adding Assert statement and decision making statement in test steps

[This is the basic steps of katalon studio,you can perform varios automation related activity using this powerful automation tool.]

Please let me know if you having any query related to this,For more you can visit

https://www.katalon.com/katalon-studio/

Thanks

Abhishek Roy