Vous êtes sur la page 1sur 2

package vtiger_testcases; import import import import import import import import import import import import com.thoughtworks.selenium.

*; org.junit.After; org.junit.Before; org.junit.Test; java.io.BufferedReader; java.io.BufferedWriter; java.io.FileNotFoundException; java.io.FileOutputStream; java.io.FileReader; java.io.FileWriter; java.io.IOException; java.util.regex.Pattern;

public class WriteTextFile extends SeleneseTestCase { @Before public void setUp() throws Exception { selenium = new DefaultSelenium("localhost", 4444, "*firefox", "h ttp://"); selenium.start(); } @Test public void testUntitled() throws Exception { selenium.open("www.google.com"); String filepath = "D:/FindMeHere2.txt" ; FileWriter somenewfile = CreateTxtFile(filepath); AppendTextToFile(filepath, "here is how i would append the text" ); } /* @After public void tearDown() throws Exception { selenium.stop(); }*/ public FileWriter CreateTxtFile(String fpath) throws IOException { System.out.println("Inside the Create Text File method :::: "); //String fpath = "d:/mynewtextfile.txt"; FileWriter mynewfile = new FileWriter(fpath, false); //FileOutputStream fout = new FileOutputStream(fpath); mynewfile.write("This is a new text file , that i wrote into ") ; mynewfile.close(); return mynewfile ; } public void AppendTextToFile(String filepath, String testtext) t hrows IOException { System.out.println("Inside the Append Text to File meth od :::: "); //FileOutputStream fout = new FileOutputStream(fpath); FileWriter fstream = new FileWriter(filepath,true); BufferedWriter out = new BufferedWriter(fstream);

out.newLine(); out.write(testtext); //Close the output stream out.close(); } }

Vous aimerez peut-être aussi