­

This blog is for Automation Test Engineers

Friday, 16 March 2018

Writing data into excel sheet

FileInputStream fis=new FileInputStream("E:\\data.xlsx");              Workbook wb=WorkbookFactory.create(fis); Sheet s=wb.getSheet("test");//sheet name s.createRow(1).createCell(1).setCellValue("Java"); FileOutputStream fos = new  FileOutputStream("E:\\data.xlsx");  wb.write(fos);  fos.close(); System.out.println("Success");                  } ...
2

How to click on Hyperlink

WebDriver driver= new FirefoxDriver(); driver.get("https://www.google.com"): driver.findElement(By.linkText("ಕನ್ನಡ")).click()...
0

Different types of navigation command

1)driver.navigate().back(): This command takes back the user to previous page of the application. 2)driver.navigate().forward(): This command navigates the user to next page of application 3)driver.navigate().refresh(); This command refreshes the current webpage 4)driver.navigate().to():This command allows the user to launch a new web browser window and navigates to specified URL Eg: driver.navigate().to("https://www.google.co.in/"); ...
0

How to enter semicolon

String keys=keys.chord(Keys.SHIFT, Keys.SEMICOLON); ...
0

How to press Shift+Tab

String keys=keys.chord(Keys.SHIFT, Keys.TAB); ...
0

How do u read text from hidden element

First we should move cursor over element where element is hidden and we can use getText() method to get the text from hidden elemen...
0

Windows scroll up/down

WebDriver driver= new FirefoxDriver(); driver.get("https://www.flipkart.com/"): JavascriptExceutor js=new JavascriptExceutor (); //scroll up js.executeScript("window.scrollBy(0,450)",""); //scroll down js.executeScript("window.scrollBy(450,0)","")...
0

How to get size of object

WebDriver driver= new FirefoxDriver(); driver.get("https://www.google.com"): WebElement button=driver.findElement(By.name("btnK")); System.out.print(button.getSize()); ...
0

How to get tag name

WebDriver driver= new FirefoxDriver(); driver.get("https://www.google.com"): WebElement button=driver.findElement(By.name("btnK")); System.out.print(button.getTagName()); ...
0

How to get text of object

WebDriver driver= new FirefoxDriver(); driver.get("https://www.google.com"): WebElement button=driver.findElement(By.name("btnK")); System.out.print(button.getText()); ...
0

How to get location of object

WebDriver driver= new FirefoxDriver(); driver.get("https://www.google.com"): WebElement button=driver.findElement(By.name("btnK")); System.out.print(button.getLocation()); ...
0

How to get hashcode of object

WebDriver driver= new FirefoxDriver(); driver.get("https://www.google.com"): WebElement button=driver.findElement(By.name("btnK")); System.out.print(button.hashcode()); ...
0

How to handle popup in selenium

WebDriver driver =new FirefoxDriver(); driver.manage().window().maximize(); driver.get("https://www.vrlbus.in/vrl2013/register_customer.aspx"); WebElement firstbox=driver.findElement(By.name("FIRSTNAME")); firstbox.sendKeys("chaitra"); driver.findElement(By.xpath("//input[@type='submit']")).click(); String alertmessage=driver.switchTo().alert().getText(); System.out.print(alertmessage); ...
0

How to get title of page

System.setProperty("webdriver.ie.driver","E:\\IEDriverServer.exe"; Webdriver driver=new InternetExplorerDriver(); driver.get("https://www.flipkart.com/"); String title=driver.getTitle(); System.out.println(title);...
0

How do you open an application in IE broser

System.setProperty("webdriver.ie.driver","E:\\IEDriverServer.exe"; Webdriver driver=new InternetExplorerDriver(); driver.get("https://www.flipkart.com/");...
0

How do you open an application in chrome broser

System.setProperty("webdriver.chrome.driver","E:\\chrome.exe"); Webdriver driver=new ChromeDriver(); driver.get("https://www.flipkart.com/")...
0

How to handle Autosuggestion in selenium

Webdriver driver =new FirefoxDriver(); driver.get("https://www.google.co.in"); WebElement searchbox=driver.finElement(By.name("q")).senkeys("selenium")); List<WebElement>autosugg=driver.findElement(By.xpath("//div[contains(text(),'selenium')] for(int i=1;i<autosugg.size();i++){ System.out.println(autosugg.get(i).getText()); } //Number of ads to offset the result offset_9033 = 0; //Request ads for a specific keyword keyword_9033 = ''; //Request ads for a particular publisher subid sid_9033=''; //Pass click through a secondary...
0

How to minimize the screen size

Webdriver driver =new FirefoxDriver(); driver.get("https://www.google.co.in"); driver.manage().window().setPosition(new Point(0,-500)); driver.close();...
0

How to maximize the screen in selenium

Webdriver driver =new FirefoxDriver(); driver.get("https://www.google.co.in"); driver.manage().window().maximize(); driver.close()...
0

Thursday, 15 March 2018

How to clear textbox in selenium

Webdriver driver=new FirefoxDriver(); driver.get("https://www.google.co.in/"); WebElement searchbox=driver.finElement(By.name("q")).senkeys("selenium")); searchbox.sendkeys(keys.chord(Keys.Control,"a")); searchbox.sendkeys(keys.BACK_SPACE);  OR searchbox.clear(); driver.close(); ...
2

Fibonacci Sequence

int first=0; int second=1; int next; Scanner in=new Scanner(System.in); System.out.println("Enter the number"); int n=in.nextInt(); for(int i=o;i<n;i++){ next=first+second; System.out.println(next); first=second; second=next; ...
0

Assertions in TesNG

Assertions plays very important role. It helps to verify the condition of your test. It the condition is not satisfied it fails the test and it will stop the execution. Different TestNG Asserts Statements: 1)assertEquals(boolean actual,boolean expected) : Takes two boolean arguments and checks whether both are equal else it fails the test. 2)assertEquals(boolean actual,boolean expected, java.lang.String message): Takes two boolean arguments and checks whether both are equal else it fails the test with given...
0

Other Annotations in TestNG

alwaysRun If set to true, this test method will always be run even if it depends on a method that failed. dataProvider The name of the data provider for this test method. dataProviderClass The class where to look for the data provider. If not specified, the data provider will be looked on the class of the current test method or one of its base classes. If this attribute is specified, the data provider method needs to be static on the specified class. dependsOnGroups The list of groups...
0

TestNG Suite

Inorder to execute multiple TestNG classes automatically one after the another you can use TestNG Suite. TestNG suite is an xml file which contains list of TestNG classes which are to be executed. In order to create TestNG suite, right click on the package or on the java project go to TestNG---->Select convert to TestNG and click on finish which creates TestNG.xml inside the java project as shown below: ?xml version="1.0" encoding="UTF-8"?> <suite name="Suite" parallel="false"> <test name="Testone"> <classes> <class name="com.Firstpackage.Test...
0

How to execute first TestNG class

1)   Select the Java project in the Eclipse and go to Run | Run Configuration.Run Configurations window will be opened. 1)   Select TestNG in the given options and select a New_configuration. 3) Please notice that TestNG plugin provides multiple options for running your test cases as follows: ·         Class: Using this option you can provide the class...
0

Examples for all annotaions

import org.testng.annotations.BeforeMethod; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeSuite; import org.testng.annotations.AfterSuite; public class Test { @BeforeMethod public void beforeMethod() { System.out.println("Before Method"); } @AfterMethod public void afterMethod() { System.out.println("After Method"); } @BeforeClass public void...
0