Monday 30 January 2017

Parent and Child POM.xml


We can maintain parent and child pom.xml files for better and clearer dependency management in larger sized projects.

All the dependencies in the parent pom will be available in child pom by default and child pom dependencies overrides if mismatch happens.

Note : Directory structure has no dependency over parent and child relation of pom files.

Folder structure:
|commonapp
|  -----pom.xml
|springapp
| ------pom.xml

Parent Pom.xml
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.concretepage.app</groupId>
  <artifactId>commonapp</artifactId>
  <version> 1.0-SNAPSHOT</version>
</project>

Child pom.xml
<project>
  <parent>
    <groupId>com.concretepage.app</groupId>
    <artifactId>commonapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../commonapp/pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>springapp</artifactId>
</project>



Adding a private/ multiple repositories into pom.xml

Now a days most of the companies are implementing utilities and converting them into jar files and maintaining in the company repositories (similar to maven repo which is private)

As part of the framework, we might need to use Maven and our Private repo for dependency management.
Here is the solution for the problem.

In pom.xml, add below code.
<repositories>
    <repository>
      <id>my-priavte-repo1</id>
      <name>My comapny private repositiy</name>
      <url>http://MyComapanyName.ProjectName.Extension</url>
    </repository>    
</repositories>

Then adding dependencies is similar to Maven.


That’s all.

Friday 27 January 2017

you want to write executable selenium code?

- Create a class ( assume name Test.java)
- Write your selenium code in public static void main method.
- Right click on Test.java file and select Export option
- Choose "Runnable JAR file" under Java
- Next
- Choose Export destination
- Package required libraries into generated JAR

Thursday 26 January 2017

Handle proxy settings in selenium webDriver

Why proxy?

To hide the IP address of the client computer so that it can surf anonymous, this is mostly for security reasons. A proxy server can act as an intermediary between the user's computer and the Internet to prevent from attack and unexpected access

String PROXY = "localhost:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
     .setFtpProxy(PROXY)
     .setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);

WebDriver driver = new InternetExplorerDriver(cap);

Tuesday 24 January 2017

Appium setup ( Windows OS )

  1.  connect your Android mobile using USB data cable, then choose file transfer / camera option in the Use USB for.



2. Go to Settings -> Developper Options -> ON
Then Set these options to ON ( Stay awake, USB debugging, Allow Mock Locations)


1.       Install Java 8
2.       Install Eclipse Neon
3.       Install Eclipse ADT plugin (To use Android SDK with Eclipse), this step will ask for Android SDK installation.  https://dl-ssl.google.com/android/eclipse/ (select all check box of developer tools)
4.       After step 3, eclipse restarts and asks for Android SDK download (Opens up Android Manager window, here Choose the appropriate SDK version and go for install)
5.       Set Environment variables.
a.       User Variable: ANDROID_HOME: C:\Users\myprofile\android-sdks
b.       System Variable: Path: C:\Users\myprofile\android-sdks\tools\; C:\Users\myprofile\android-sdks\platform-tools\
Test: open command window :/> android      (opens Android SDK Manager)
6.       Install Microsoft .Net Framework ( Latest )
7.       Install Node Js (https://nodejs.org/en/download/)
8.       Connect Android Device With PC In USB Debugging Mode To Run Appium Test
a.       Settings – About Phone –Build Number ( tap 7 times)
b.       Settings – Developer Options – USB debugging – check it.
Test: Cmd:> adb devices ( this shows your mobile id)
9.       Install http://pdanet.co/ (only, if you are not able to connect to your mobile device with step 8 )

10.   Install Appium http://appium.io/

Wednesday 11 January 2017

java robot class


if you want to perform some click / enter action over one element in  browser


option 1: slenium

option 2: slenium Action class

option 3: java script / jquerry

option 4: java robot class

import java.awt.Robot;

Robot robot1 = new Robot();
robot1.delay(3000);
robot1.keyPress(KeyEvent.VK_ENTER);

book my show - play song when a theater got added

package bookmyshow;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Test {

public static void main(String[] args) throws Exception {

while (true) {
URL myUrl = new URL(
URLConnection yc = myUrl.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream(), "UTF-8"));
String inputLine;
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
a.append(inputLine);
in.close();
String str1 = a.toString();
boolean result = str1.indexOf("BR Hitech") > 0;
if (result) {

File audioFile = new File("C:\\Users\\KKasthuri\\Downloads\\aa.wav");
Clip audioClip;
try {
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
AudioFormat format = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
audioClip = (Clip) AudioSystem.getLine(info);

audioClip.open(audioStream);
audioClip.start();
Thread.sleep(10000);
audioClip.close();

} catch (Exception ex) {
System.out.println("Erffdfsg the audio file.");
ex.printStackTrace();
}

System.out.println("theater added");
}
Thread.sleep(5000);
}
}

}

Soft assertions vs Hard assertions in TestNG

When hard assertion will fail Inside any test method, remaining execution of that specific test method will be aborted. Now If you wants to continue remaining test part execution even If assertion fails and also you wants to report assertion failure In testng result report then you can use testng soft assertion method.

syntax:

import org.testng.asserts.SoftAssert;
SoftAssert s_assert = new SoftAssert();
s_assert.assertEquals(actual, expected);

collect javascript errors (those coming up in the console) from firefox through java.

http://stackoverflow.com/questions/24593872/how-to-get-browser-console-error-messages-using-selenium-webdriver-java

https://github.com/mguillem/JSErrorCollector