There are two main ways to create Java Strings. One is by creating a String literal (see top line in picture below). The other is to explicitly create a new Object in memory (See second line below). I will avoid going into detail about how these differ as it involves discussing aliasing and how Java saves memory. Note: Unlike some other programming languages, in Java Strings must be enclosed in double quotes. Single quotes are used for chars, a primitive data type.
Important Methods of a Java String
String Concatenation
To concatenate Strings (join to Strings), the easiest way to do it is just use the + operator as shown in the example below
tring abcAsVariable ="abc";
String defAsVariable ="def";
String abcdef = "abc" + "def";
You could achieve the same concatenation by using the variables as shown in the next line.
String abcdef = defAsVariable + abcAsVariable ;
How to Declare and Initialize a String in Java
import java.awt.Label;
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.Number;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class Jmeter {
public static void main(String asp[]) throws BiffException, IOException
{
Workbook workbook = Workbook.getWorkbook(new File("C:\\Frame11.xls"));
WritableWorkbook wbook1 = Workbook.createWorkbook(new File("C:\\Nitin.xls"));
Sheet sheet = workbook.getSheet(0);
Cell cell =sheet.getCell(0, 0);
Cell cell1 =sheet.getCell(0, 1);
Cell cell2 =sheet.getCell(0, 2);
String s = cell.getContents();
String s1 = cell1.getContents();
String s2 = cell2.getContents();
System.out.print("HEllo "+s+" "+s1+" "+s2);
WritableSheet ws = wbook1.createSheet("FIRSTSHEET", 0);
Number num = new Number(0, 1, 25.5285);
wbook1.write();
wbook1.close();
}
WRITING DATA TO EXCEL(Code)
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.BiffException;
public class Jmeter {
public static void main(String asp[]) throws BiffException, IOException
{
Workbook workbook = Workbook.getWorkbook(new File("C:\\Frame11.xls"));
Sheet sheet = workbook.getSheet(0);
Cell cell =sheet.getCell(0, 0);
Cell cell1 =sheet.getCell(0, 1);
Cell cell2 =sheet.getCell(0, 2);
String s = cell.getContents();
String s1 = cell1.getContents();
String s2 = cell2.getContents();
System.out.print("HEllo "+s+" "+s1+" "+s2);
}
};
READING DATA FROM EXCEL(Code)
Step 1: For that first we need to import SeleniumServer class
Which exist in following package.
Import org.openqa.selenium.server.*;
Step 2: Now we need to create SeleniumServer object.
SeleniumServer sr = new SeleniumServer(rc);
Here I am creating selenium server object and passing configuration object as an argument.
Step 3: We need to boot selenium server.
sc.boot();
Step 4: Stating Selenium Server
sc.start();
STARTING SELENIUM SERVER using Java code
While working with selenium server first we need to setup configuration of selenium server, like on which port the server will run, Avoid proxy setting, start logs etc.
For working with Selenium server configuration, we need to perform following tasks.
1 Add selenium server jar file in build path of current project.
2 Import org.openqa.selenium.sever.RemoteControlConfiguration;
Here we have imported selenium sever Rcmote Control Configuration Class, we can need to create object of that class and then we can use methods of the class to ser remote control server configuration.
3 Create RemoteControlConfiguration object
RemoteControlConfiguration rc = new RemoteControlConfiguration();
4 Set Port
rc.setPort(4444);
5 Set Proxy
rc.setAvoidProxy(true)
6 Set Browser side logs
rc.setBrowserSideLogsEnabled(true)
By this way we can set as much settings as we want in RemoteControlConfiguration
Selenium Server settings
For setting Remote Control Server configuration,
1 Create a Remote Control Configuration object.
2 We have multiple methods for that
3 We can use method like setPort to ser port etc, like this we have many properties that can be use for server settings.
4 We can pass these configuration object to server pobject.
For Enable/ Disable Java script etc
1 We can use user-extensions.js file and these we can set different browser settings.
For rest of the work, we can use Twist.properties file
The Selenium configurations are defined in the twist.properties file. This file can be accessed by searching for it using Ctrl+Shift+R while at the workbench or by switching to the Java perspective.
Working With Server Configuration
Subscribe to:
Posts
(
Atom
)