Posts

Database Connection

 class DbConnection {     {               Connection con=DriverManager.getConnection( "jdbc:postgresql://" + hostname + ":" + port + "/" + dbname , username , password );          Statement stmt=con.createStatement();          ResultSet rs=stmt.executeQuery("select * from students where id=123456");          while(rs.next())          {                 System.out.println(rs.getString(1));           }     }     catch(SQLException e)     {          e.printStackTrash();          } }

Locators in selenium(for locating web element-static method in By class)

2 locator inspect element on web page <input placeholder="Patient First Name" maxlength="30" class="form-control jqName" size="30" type="text" name="appointment[patient_ attributes][firstname]" id="appointment_patient_ attributes_firstname"> id unique driver.findElement(By.id(" appointment_patient_ attributes_firstname")); class driver.findElement(By.class(" form-control jqName")); classname driver.findElement(By. className("appointment[ patient_attributes][firstname] ")); cssSelector() WebElement ref = driver.findElement(By. cssSelector("input[class=' form-control jqName']")); <a href=" https://www.credihealth. com/doctors ">Doctors Network</a> linkText() WebElement ref = driver.findElement(By. linkText("Doctors Network")); partiallinktext() WebElement ref = driver.findElement(By. partialLinkText("Doctors Net")); tagName ...

Collection Framework

Image
Class Name Duplicate Allowed Null Insertion Order of Insersion Maintained Index/Hashcode Default capacity Data Structure Arraylist ✓ ✓ ✓ Index ✓ 10 Re-sizable data structure Vector ✓ ✓ ✓ Index ✓ 10 Doubly Data Structure Linked List ✓ ✓ ✓ Index X Linear Data Structure Hash Set X ✓ X Hash Code X Hash Table Data Structure Linked HashSet X ✓ ✓ Hash Code X Hybrid Data Structure Tree Set X X X Hash Code X Balanced Data Structure Priority Queue ------ ------ ------ ------ ------ ------ Collection Framework -->Collection: Collection is a frame used to perform Insertion and retrieval operation of an unique element as an single entity. -->If you wan...

Emulate Chrome Browser into mobile View by Using Selenium part-1

                    WebDriver driver ;           ChromeOptions chromeOptions ;   @BeforeClass     public void Resources()   {                                    System. setProperty ( "webdriver.chrome.driver" , "/Users/abc/Desktop/chromedriver/chromedriver" );   Map<String, String> mobileEmulation = new HashMap<>();     mobileEmulation .put( "deviceName" , "iPhone 6/7/8" );     chromeOptions = new ChromeOptions();   chromeOptions .setExperimentalOption( "mobileEmulation" , mobileEmulation );   driver = new ChromeDriver( chromeOptions );   }

Run Selenium Tests in Internet Explorer

 package com.qa.tests; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class RunTestsInternetExplorer { WebDriver driver; @BeforeClass public void loadResources() { //---------Open in Internet Explorer browser------- //for downloading IE Driver exe file visit "https://www.selenium.dev/downloads/" System.setProperty("webdriver.ie.driver","D://driversBrowser//IEDriverServer_Win32_3.150.1//IEDriverServer.exe"); driver = new InternetExplorerDriver(); } @Test public void navUrlForTest() { for(int i=0;i<50;i++) { driver.get("https://letstryselenium.blogspot.com"); } } }

Run Selenium Tests on Chrome Browser

package com.qa.tests; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class RunTestsOnChrome { WebDriver driver; @BeforeClass public void loadResources() { //---------Open in chrome browser------- //for downloading chromeDriver exe file visit "https://chromedriver.chromium.org/" System.setProperty("webdriver.chrome.driver", "D://driversBrowser//chromedriver_win32//chromedriver.exe"); driver = new ChromeDriver(); } @Test public void navUrlForTestGA() { for(int i=0;i<50;i++) { driver.get("https://letstryselenium.blogspot.com"); } } }

Write data into excel file by using maven poi dependencies.

Image
 package com.qa.tests; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; public class WriteDataExcel  { public static void main(String[] args) throws Exception { String str="D:\\excel\\Book1.xlsx"; FileInputStream file=new FileInputStream(str); Workbook book = WorkbookFactory.create(file); Sheet sheet = book.getSheetAt(1); for(int i=1;i<=16;i++) { Row row = sheet.createRow(i); for(int j=0;j<2;j++) { Cell cell = row.createCell(j); if(j%2==0) { cell.setCellValue("username"+i); } else { cell.setCellValue("password"+i); } } } file.close(); FileOutputStream fis=new FileOutputStream(new File(str)); book.write(...