Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TestCaseAnalyser
{
/**
* @param args
*/
public static void main(String[] args) {
TestCaseAnalyser analyser = new TestCaseAnalyser();
List<TestCase> testCases = analyser.loadTestCases(new File("DeineDatei.txt"));
analyser.wrapToHtml(new File("DeineHtmlDatei.html"), testCases);
}
/**
* @param file
* @return
*/
public List<TestCase> loadTestCases(File file) {
List<TestCase> testCases = new ArrayList<TestCase>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String line;
while((line = reader.readLine()) != null) {
int countSuccess = countWord(line, "is successfull", false);
int countNotSuccess = countWord(line, "not successfull", false);
testCases.add(new TestCase(line, countSuccess, countNotSuccess));
}
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
} finally {
if(reader != null) {
try {
reader.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
return testCases;
}
/**
* @param string
* @param searched
* @return
*/
public int countWord(String string, String searched, boolean caseSensitive) {
if(!caseSensitive) {
string = string.toLowerCase();
searched = searched.toLowerCase();
}
int startIndex = 0;
int wordIndex = 0;
int count = 0;
while((wordIndex = string.indexOf(searched, startIndex)) != -1) {
startIndex = wordIndex + searched.length();
count++;
}
return count;
}
/**
* @param outputFile
* @param testCases
*/
public void wrapToHtml(File outputFile, List<TestCase> testCases) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(outputFile));
for(TestCase testCase : testCases) {
System.out.println(testCase);
String testCase_id=testCase.getId();
String testCase_title=testCase.getTitle();
String testCase_url=testCase.getUrl();
String testCase_type=testCase.getType();
String testCase_message=testCase.getResultMessage();
writer.write("<h2>");
for (int i=0; i<testCase_id.length(); i++){
writer.write((byte)testCase_id.charAt(i));
}
writer.write("</h2>");
writer.newLine();
writer.write("Titel: ");
for (int i=0; i<testCase_title.length(); i++){
writer.write((byte)testCase_title.charAt(i));
}
writer.write("<br/><br/>");
writer.newLine();
writer.write("URL: ");
for (int i=0; i<testCase_url.length(); i++){
writer.write((byte)testCase_url.charAt(i));
}
writer.write("<br/><br/>");
writer.newLine();
writer.write("Type: ");
for (int i=0; i<testCase_type.length(); i++){
writer.write((byte)testCase_type.charAt(i));
}
writer.write("<br/><br/>");
writer.newLine();
writer.write("Message: ");
for (int i=0; i<testCase_message.length(); i++){
writer.write((byte)testCase_message.charAt(i));
}
writer.write("<br/><br/>");
writer.newLine();
}
writer.flush();
} catch(IOException e) {
e.printStackTrace();
} finally {
if(writer != null) {
try {
writer.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
}
private final class TestCase
{
private final String name;
private final int countSuccess;
private final int countNotSuccess;
/**
* @param name
* @param countSuccess
* @param countNotSuccess
*/
public TestCase(String name, int countSuccess, int countNotSuccess) {
this.name = name;
this.countSuccess = countSuccess;
this.countNotSuccess = countNotSuccess;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the countSuccess
*/
public int getCountSuccess() {
return countSuccess;
}
/**
* @return the countNotSuccess
*/
public int getCountNotSuccess() {
return countNotSuccess;
}
}
}