Paste Multiline String
Eclipse has an option so that copy-paste of multi-line text into String literals will result in quoted newlines:
Preferences/Java/Editor/Typing/ enable Escape text when pasting into a string literal"
// Create an ArrayList of ArrayLists of Integers
ArrayList<ArrayList<Integer>> my2DArrayList = new ArrayList<ArrayList<Integer>>();
// add in a few ArrayLists. These contain the "rows" of the 2D ArrayList
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
my2DArrayList.add(new ArrayList<Integer>());
// you can retrieve rows using get(), then treat that 1D arrayList as the column.
my2DArrayList.get(0).add(1);
my2DArrayList.get(0).add(2);
my2DArrayList.get(1).add(3);
my2DArrayList.get(1).add(4);
my2DArrayList.get(1).add(0);
my2DArrayList.get(2).add(5);
// my2DArrayList now contains this:
// row 0: 1, 2
// row 1: 3, 4, 0
// row 2: 5
// to retrieve a specific element, you need to first get the ArrayList of the row you want, then retrieve the column from that arraylist you want
// get element at row 1 and column 2
int number = my2DArrayList.get(1).get(2);
If you declare your @DataProvider as taking a java.lang.reflect.Method as first parameter, TestNG will pass the current test method for this first parameter. This is particularly useful when several test methods use the same @DataProvider and you want it to return different values depending on which test method it is supplying data for.
For example, the following code prints the name of the test method inside its @DataProvider:
@DataProvider(name = "dp")
public Object[][] createData(Method m) {
System.out.println(m.getName()); // print test method name
return new Object[][] { new Object[] { "Cedric" }};
}
@Test(dataProvider = "dp")
public void test1(String s) {
}
@Test(dataProvider = "dp")
public void test2(String s) {
}
and will therefore display:
test1
test2
public class testng { public Object[][] dp1() { return new Object[][] {new Object[] { "a", "b" },new Object[] { "c", "d" } }; } public Object[][] dp2() { return new Object[][] { new Object[] { "e", "f" },new Object[] { "g", "h" } }; } @DataProvider public Object[][] dp() { List
File profileDir = new File("D:\\profile"); //("path/to/top/level/of/profile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setPreferences(extraPrefs);
WebDriver driver = new FirefoxDriver(profile);
C:\Users\User>javac.exe
'javac' is not recognized as an internal or external command, operable program or batch file.
C:\Users\User>javac Usage: javac where possible options include: -g Generate all debugging info ...
C:\Users\Catalin>echo %CLASSPATH% C:\Program Files\Java\jdk1.6.0_16\jre\lib C:\Users\User>echo %JAVA_HOME% C:\Program Files\Java\jdk1.6.0_16 C:\Users\User>echo %PATH%
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class test_table { public static void main(String[] args) throws InterruptedException { WebDriver driver=new FirefoxDriver(); driver.get("http://www.w3schools.com/html/html_tables.asp"); String s=""; int i,j; for( i=1;i<=5;i++){ for( j=1;j<=4;j++) { System.out.println(i+" ,"+ j); if (i==1) s=s+" "+driver.findElement(By.xpath("//table[@class='reference']//tr["+i+"]//th["+j+"]")).getText(); else s=s+" "+driver.findElement(By.xpath("//table[@class='reference']//tr["+i+"]//td["+j+"]")).getText(); } s=s+"\n"; } System.out.println(s); } }
System.out.println((new File("")).getAbsolutePath());-----------------OR -----------------
File currDir = new File("."); String path = currDir.getAbsolutePath(); System.out.println(path);
import java.awt.EventQueue; public class gui { JFrame frame; JButton btnNewButton ; JTextArea textArea; SpringLayout springLayout; JTextPane textPane; // gui(){ initialize();} public void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); springLayout = new SpringLayout(); frame.getContentPane().setLayout(springLayout); btnNewButton = new JButton("New button"); springLayout.putConstraint(SpringLayout.NORTH, btnNewButton, 113, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, btnNewButton, 132, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(btnNewButton); textPane = new JTextPane(); textPane.setText("Hi"); btnNewButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if(textPane.isDisplayable()==false){ frame.getContentPane().add(textPane); springLayout.putConstraint(SpringLayout.NORTH, textPane, 31, SpringLayout.SOUTH, btnNewButton); springLayout.putConstraint(SpringLayout.WEST, textPane, 148, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, textPane, 248, SpringLayout.WEST, frame.getContentPane()); } else frame.getContentPane().remove(textPane); frame.validate(); frame.repaint(); }}); } }Code calling GUI
class Test { public static void main(String[] args) { gui obj=new gui(); obj.initialize(); obj.frame.setVisible(true); }