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