import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Takesnapshot {
public static void main(String[] args) throws IOException {
// Intialize Web driver
WebDriver driver = new FirefoxDriver();
//Maximizw window
driver.manage().window().maximize();
//Launch website
driver.get("http://www.yahoo.com");
// wait for page loads
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Takes snapshort
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Save screen shot desired location
FileUtils.copyFile(scrFile, new File("screenshot.png"));
// close wbe driver
driver.quit();
}
}
How to take snapshot in Selenium WebDriver using java.
How to read pdf content in Java
import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.util.PDFTextStripper; public class Readcontentfrompdf { public static void main(String[] args) throws IOException { PDDocument pd; // load pdf file pd=PDDocument.load(new File("Specification.pdf")); PDFTextStripper pdftext = new PDFTextStripper(); System.out.println("Text =: " + pdftext.getText(pd)); } }
How to read all files in a folder in Java.
import java.io.File; public class Readallfiles { //File location static File mainFolder = new File("D:\\Images"); public static void main(String[] args) { Readallfiles lf = new Readallfiles(); lf.getFiles(lf.mainFolder); } public void getFiles(File f){ File files[]; if(f.isFile()) // File name System.out.println(f.getName()); else{ files = f.listFiles(); for (int i = 0; i < files.length; i++) { getFiles(files[i]); } } } }
How to perform load testing on MS SQL Server using jmeter.
2. Open Jmeter from : apache-jmeter_home/bin/jmeter.bat or ApacheJMeter.jar
3. Add Users
Select the Test Plan, right click on Test Plan, select Add> Threads(Users)> Thread Group
Set up the following fields for Users:
a. Set value for Numbers of Threads(users): 5
b. Set value for Ram-up Periods : 2.
It means that 5 users connect to MYSQL server withine 2 seconds.
4.Add JDBC Connection Configuration
Right click on the 'Thread Group', select Add > Config Element > JDBC Connection Configuration.
Set up the following fields for MySQL database:
a. Variable name bound to pool. This needs to uniquely identify the configuration. It is used by the JDBC Sampler to identify the configuration to be used. We have named it as 'mssqlpool'
b. Database URL: jdbc:sqlserver://host:port;DatabaseName=dbname
c. JDBC Driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver
d. Username: username of database
e. Password: password of database
f.The other fields can be left as the defaults
5. Add JDBC Requests
Right click on the 'Thread Group', select Add > Sampler > JDBC Request.
Then, select this new element to view its Control Panel. Edit the properties as below:
a. Enter the Pool Name: mssqlpool (same as in the configuration element)
b. Query Type: Select statement
c. Enter the SQL Query String field.
6. Adding a Listener to View/Store the Test Results
Right click on the 'Thread Group', select Add --> Listener --> View Results Tree and Summary Report
Save the test plan, and run the test with the menu Run --> Start or Ctrl+R
How to perform load testing on Postgresql Database using jmeter.
2. Open Jmeter from : apache-jmeter_home/bin/jmeter.bat or ApacheJMeter.jar
3. Add Users
Select the Test Plan, right click on Test Plan, select Add> Threads(Users)> Thread Group
Set up the following fields for Users:
a. Set value for Numbers of Threads(users): 5
b. Set value for Ram-up Periods : 2.
It means that 5 users connect to MYSQL server withine 2 seconds.
4.Add JDBC Connection Configuration
Right click on the 'Thread Group', select Add > Config Element > JDBC Connection Configuration.
Set up the following fields for MySQL database:
a. Variable name bound to pool. This needs to uniquely identify the configuration. It is used by the JDBC Sampler to identify the configuration to be used. We have named it as 'Postgresqlpool'.
b. Database URL: jdbc:postgresql://IPAddress:PortNo/DatabaseName?autoReconnect=true
c. JDBC Driver class: org.postgresql.Drive
d. Username: username of database
e. Password: password of database
f.The other fields can be left as the defaults
5. Add JDBC Requests
Right click on the 'Thread Group', select Add > Sampler > JDBC Request.
Then, select this new element to view its Control Panel. Edit the properties as below:
a. Enter the Pool Name: Postgresqlpool (same as in the configuration element)
b. Query Type: Select statement
c. Enter the SQL Query String field.
6. Adding a Listener to View/Store the Test Results
Right click on the 'Thread Group', select Add --> Listener --> View Results Tree and Summary Report
Save the test plan, and run the test with the menu Run --> Start or Ctrl+R
How to perform load testing on Mysql Database using jmeter.
2. Open Jmeter from : apache-jmeter_home/bin/jmeter.bat or ApacheJMeter.jar
3. Add Users
Select the Test Plan, right click on Test Plan, select Add> Threads(Users)> Thread Group
Set up the following fields for Users:
a. Set value for Numbers of Threads(users): 5
b. Set value for Ram-up Periods : 2.
It means that 5 users connect to MYSQL server withine 2 seconds.
4.Add JDBC Connection Configuration
Right click on the 'Thread Group', select Add > Config Element > JDBC Connection Configuration.
Set up the following fields for MySQL database:
a. Variable name bound to pool. This needs to uniquely identify the configuration. It is used by the JDBC Sampler to identify the configuration to be used. We have named it as 'dbconnectionpool'
b. Database URL: jdbc:mysql://IP:3306/databasename
c. JDBC Driver class: com.mysql.jdbc.Driver
d. Username: root
e. Password: password for root
f.The other fields can be left as the defaults
5. Add JDBC Requests
Right click on the 'Thread Group', select Add > Sampler > JDBC Request.
Then, select this new element to view its Control Panel. Edit the properties as below:
a. Enter the Pool Name: dbconnectionpool (same as in the configuration element)
b. Query Type: Select statement
c. Enter the SQL Query String field.
6. Adding a Listener to View/Store the Test Results
Right click on the 'Thread Group', select Add --> Listener --> View Results Tree and Summary Report
Save the test plan, and run the test with the menu Run --> Start or Ctrl+R