How can ı delete the history in the allure testng but not in the terminal, we can use code - selenium

ı want to delete my data test history in the allure testng but not in the terminal, ı want to use some functions or any annotation in my java code

Try this:
public void deleteDirectory(String directoryPath) throws IOException {
Path path = Paths.get(directoryPath);
try (Stream<Path> walk = Files.walk(path)) {
walk
.sorted(Comparator.reverseOrder())
.forEach(this::deleteTargetDirectory);
}
}
private void deleteTargetDirectory(Path path) {
try {
Files.delete(path);
} catch (IOException e) {
System.err.printf("Unable to delete this path : %s%n%s", path, e);
}
}

Related

Intellj recognizing .wav files as plain text

https://i.stack.imgur.com/2IIvj.png
So I'm trying play a sound everytime a letter is typed on screen. The code is definately correct since I copied it from a reliable source online. The only problem is I keep getting the (The system cannot find the path specified) error. Intellij recognizes .wav files as plain text for some reason. Is there a fix to this? Im I doing something wrong? Nothing I searched for works. Here is the code I use :
private class SoundEffect{
Clip clip;
public void setFile(String path) {
try {
File file = new File(path);
AudioInputStream sound = AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(sound);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
public void play(){
clip.setFramePosition(0);
clip.start();
}
}
I am getting the error when I use the setFile method.

I am not able to attach screenshots to extent reports. What is the solution?

#AfterMethod
public void getResult(ITestResult result) throws Exception{
if(result.getStatus() == ITestResult.FAILURE)
{
extentlogger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() +
" - Test Case Failed", ExtentColor.RED));
try {
// get path of captured screenshot using custom failedTCTakeScreenshot method
String screenshotPath = takeSnapShot(result);
extentlogger.fail("Test Case Failed Snapshot is below " +
extentlogger.addScreenCaptureFromPath(screenshotPath));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
The above code is the code I'm using after method in TestNG. Am I doing anything wrong?enter image description here
You don't have any method named as takeSnapShot or its not declared as public:
Create a method in base class with below content or just directly add below code in the aftermethod hook by replacing takeSnapShot step:
//Convert web driver object to TakeScreenshot
TakesScreenshot scrShot =((TakesScreenshot)webdriver);
//Call getScreenshotAs method to create image file
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);
//Move image file to new destination
File DestFile=new File(fileWithPath);
//Copy file at destination
FileUtils.copyFile(SrcFile, DestFile);

Passing java.security.auth.login.config to Mobilefirst Patform Server

How can we pass following parameter to Mobilefirst Development Server?
-Djava.security.auth.login.config=login.config
I have tried adding it to jvm.options file, and it seems it is passed as parameter without effect.
Following is the code I am trying to execute, and sample of login.config file.
Java code to execute in login module or adapter.
LoginContext context = new LoginContext("SampleClient", new CallbackHandler() {
#Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
NameCallback callBack = (NameCallback) callbacks[0];
callBack.setName("EXAMPLE.COM");
}
});
login.config
SampleClient {
com.sun.security.auth.module.Krb5LoginModule required
default_realm=EXAMPLE.COM;
};
Adding following code before login worked.
try {
Configuration config = Configuration.getConfiguration();
config.getAppConfigurationEntry("SampleClient");
URIParameter uriParameter = new URIParameter(new java.net.URI("file:///path_to_your_file/login.conf"));
Configuration instance = Configuration.getInstance("JavaLoginConfig", uriParameter);
Configuration.setConfiguration(instance);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}

Error: file doesn't exist

Now am working on a project where I need to create a folder in sdcard which am able to do. Also I need to hide/unhide it according to need. The code is working fine on emulator but not in device this is my code what went wrong ?
public class FolderCreate extends MIDlet {
private Form form;
private Display display;
FileConnection fc;
String path;
public void startApp() {
form = new Form("Hello World");
String msg = "Hello World!!!!!!!";
form.append(msg);
display = Display.getDisplay(this);
display.setCurrent(form);
System.out.println("WWWW");
try {
path = System.getProperty("fileconn.dir.memorycard");
System.out.println("Path : "+path+"/sample");
fc = (FileConnection)Connector.open(path+"/ABCD/");
if(!fc.exists())
{
fc.mkdir();
System.out.println("directory created");
}
} catch (IOException e) {
// TODO Auto-generated catch block
//System.out.println("ERROR "+e.getMessage());
Alert alert = new Alert("Alert");
alert.setString(e.getMessage());
display.setCurrent(alert);
}
try
{
//fc = (FileConnection)Connector.open(path+"/sample/");
if(fc.isHidden())
{
fc.setHidden(false);
}
else{
fc.setHidden(true);
}
fc.close();
}
catch (Exception e)
{
Alert alert = new Alert("Alert2");
alert.setString(e.toString());
display.setCurrent(alert);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
System.out.println("Destroyed");
notifyDestroyed();
}
}
The error am getting is: java.io.IOException: file does not exist
Check if path starts with "file://". If not, add the suffix.
path = System.getProperty("fileconn.dir.memorycard");
if (path != null && !path.startsWith("file://")) {
path = "file://" + path;
}
I think you are doing mistake at following line,
path = System.getProperty("fileconn.dir.memorycard");
When you are working with phone and SD-Card you should use e: drive for referring to SD Card as follows,
path = file:///e:/<folder-name>/

Unable to add screenshot in ReportNG HTML report

I am trying to take a screenshot for failure methods and also want to put the same in my Report, I am able to take the screenshot but unable to show the same in HTML report. Following is my code, friends any clue on this ?
public class SB1 {
private static Logger logger = Logger.getLogger(SB1.class);
WebDriver driver = new FirefoxDriver();
#Test
public void Testone() {
driver.get("http://www.google.com/");
assert false;
}
public void catchExceptions(ITestResult result) {
System.out.println("result" + result);
String methodName = result.getName();
System.out.println(methodName);
if (!result.isSuccess()) {
try {
String failureImageFileName = new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime())+ ".png";
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(failureImageFileName));
String userDirector = System.getProperty("user.dir") + "/";
Reporter.log("<a href=\""+ userDirector + failureImageFileName +"\"><img src=\"file:///" + userDirector
+ failureImageFileName + "\" alt=\"\""+ "height='100' width='100'/> "+"<br />");
Reporter.setCurrentTestResult(null);
} catch (IOException e1) {
e1.printStackTrace();
}
}
Have you set ESCAPE_PROPERTY to false? This is what you will have to do if you want reportng to post the screenshot -
private static final String ESCAPE_PROPERTY = "org.uncommons.reportng.escape-output";
and in your setUp-
System.setProperty(ESCAPE_PROPERTY, "false");
I tried this. It seems like if you set the System Property to false, it removes the escaping from the ENTIRE log... From what I can tell, the report is generated after the test, with whatever the system property is set to at the time. I want to insert the screenshot (which worked with above code) but I do not want to remove the other formatting (br tags).
You can use following code.
Reporter.log("<br>Chrome driver launched for ClassOne</br>");
Or you can use customize method, where you do not need to append the br tag everytime, use following customized method.
public void customLogReport(String testCaseDescription) throws Exception{
try{
Reporter.log("<br>" + testCaseDescription + "</br>");
}catch(Exception e){
e.printStackTrace();
}
}