Posts

How to handle new tab in selenium?

 package newTab; import java.util.ArrayList; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.testng.annotations.Test; import BaseInit.BaseInit; public class newTab extends BaseInit { @Test public static void openNewTab() throws InterruptedException { driver.get("https://www.abc.com/"); Thread.sleep(2000); driver.findElement(By.xpath("//*[@id=\"mm-0\"]/div/header/div/div/div/div[1]/div[2]/div/a")).sendKeys(Keys.CONTROL, Keys.ENTER); Thread.sleep(2000); ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles()); driver.switchTo().window(tabs.get(1)); Thread.sleep(2000); driver.switchTo().window(tabs.get(0)); } }

How to make batch file in selenium using Maven

 Generate .xml file- 1. Right click on project which you want to execute through batch file 2. Go to TestNG & click on Convert to TestNG 3. One testng.xml file will created in your project 4. Move that file to main-> resources folder 5. Right click on project & Run as Maven Clean & then Maven install          There would be below errors          - Java version is not compatible with compiler           - To change java compiler, Right click on project & go to java build path, then go to java compiler & change java execution environment variable according to error          - Need to add some xmls in Pom.xml after the <version>           <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding...

Execute the selenium script without opening browser.

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Krina Modi\\eclipse-workspace\\chromedriver.exe");                     ChromeOptions options = new ChromeOptions(); options.addArguments("--no-sandbox"); options.addArguments("headless", "window-size=1200,700"); ChromeDriver driver = new ChromeDriver(options);

How to generate cypress mocha report?

Install mocha using - npm i mocha Install mochawesome using - npm i mochawesome Install mochawesome-merge using - npm i mochawesome-merge Install mochawesome-report-generator using - npm i mochawesome-report-generator After installing above npm, it will add below  dependencies in package.json file "dependencies" : {      "cypress-multi-reporters" :  "^1.5.0" ,      "mocha" :  "^9.1.1" ,      "mochawesome" :  "^6.2.2" ,      "mochawesome-merge" :  "^4.2.0" ,      "mochawesome-report-generator" :  "^5.2.0"   } Add below options in cypress.json file "integrationFolder" :  "cypress/integration" ,    "video" :  false ,    "screebsgotsFolder" :  "cypress/reports/mochareports/assets" ,    "screenshotOnRunFailure" :  true ,    "reporter" :  "cypress-multi-reporters" , ...

How to handle frame window in selenium?

package webElementMethods; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class HandleFrameGetAttributes { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("https://jqueryui.com/draggable/"); WebElement frameBox = driver.findElement(By.xpath("//*[@id=\"content\"]/iframe")); driver.switchTo().frame(frameBox); System.out.println(driver.findElement(By.id("draggable")).getAttribute("style")); driver.switchTo().defaultContent(...

How to work with mouse hover menu in selenium?

package wdProgram; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; public class HandleMouseOverEvent { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("https://www.amway.com/"); driver.findElement(By.xpath("//html/body/div[2]/table/tbody/tr[1]/td[2]/table/tbody/tr/td[3]/ul/li/a")).click(); WebElement mainMenu = driver.findElement(By.xpath("//*[@id=\"menu\"]/li[4]/a")); WebElement subMenu = driv...

How to handle alert window?

  package wdProgram; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class HandleAlertWindow { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("http://localhost/uth/gadgetsgallery/catalog"); driver.findElement(By.linkText("create an account")).click(); driver.findElement(By.id("tdb1")).click(); String alertText = driver.switchTo().alert().getText(); System.out.println(alertText); driver.switchTo().alert().accept();   //Clicks on OK button //driver.switchTo().alert...