Executing Headless Browser Test In Different Browsers And Version In Selenium

We accept learnt how to execute JavaScript In HtmlUnit driver assay In previous post. I am equally good suggesting y'all to read how to utilisation together with run kickoff HtmlUnit driver assay In THIS POST where I accept described advantages of HtmlUnit driver against all other driver Instances. One of them Is nosotros can
choose the browser together with Its version to run selenium WebDriver test.

HtmlUnit driver allows y'all to run your tests In dissimilar browser but In hidden mode. That agency If your selected browser to run your assay Is Google chrome thence assay volition live on executed In Google chrome browser but y'all volition non run across Google chrome browser on your cover during assay execution. You tin select whatever of the bellow given browsers together with versions to run your WebDriver tests In It using HtmlUnit driver.
  • CHROME
  • FIREFOX_17
  • FIREFOX_24
  • INTERNET_EXPLORER_8
  • INTERNET_EXPLORER_9
  • INTERNET_EXPLORER_11
Syntax to select browser to run assay using HtmlUnit driver Is equally bellow.
//Initializing HtmlUnitDriver to run assay amongst INTERNET_EXPLORER_11 browser.
HtmlUnitDriver driver = novel HtmlUnitDriver(BrowserVersion.INTERNET_EXPLORER_11);

Create together with run bellow given instance In your eclipse to run across execution practically.
package Testing_Pack;  import java.util.List; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebElement; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  import com.gargoylesoftware.htmlunit.BrowserVersion;  world flat htmlDriver {    HtmlUnitDriver driver;  String pagetitle;   @BeforeTest  world void setup() throws Exception {   //Initializing HtmlUnitDriver to run assay amongst INTERNET_EXPLORER_11 browser.   HtmlUnitDriver driver = novel HtmlUnitDriver(BrowserVersion.INTERNET_EXPLORER_11);   //Enabling JavaScript of HtmlUnitDriver.   driver.setJavascriptEnabled(true);     driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);      //To shroud warnings logs from execution console.   Logger logger = Logger.getLogger("");   logger.setLevel(Level.OFF);      //Opening URL In HtmlUnitDriver.   driver.get(" ");  }   @AfterTest  world void tearDown() throws Exception {   //Closing HtmlUnitDriver.   driver.quit();  }   @Test  world void googleSearch() {     //Get electrical flow page championship using javascript executor.   JavascriptExecutor javascript = (JavascriptExecutor) driver;   String pagetitle=(String)javascript.executeScript("return document.title");     System.out.println("My Page Title Is  : "+pagetitle);      // To locate table.   WebElement mytable = driver.findElement(By.xpath(".//*[@id='post-body-8228718889842861683']/div[1]/table/tbody"));   // To locate rows of table.   List<WebElement> rows_table = mytable.findElements(By.tagName("tr"));   // To calculate no of rows In table.   int rows_count = rows_table.size();    // Loop volition execute till the final row of table.   for (int row = 0; row < rows_count; row++) {    // To locate columns(cells) of that specific row.    List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));    // To calculate no of columns(cells) In that specific row.    int columns_count = Columns_row.size();    System.out.println("Number of cells In Row " + row + " are "+ columns_count);     // Loop volition execute till the final jail cellular telephone of that specific row.    for (int column = 0; column < columns_count; column++) {     // To recollect text from that specific cell.     String celtext = Columns_row.get(column).getText();     System.out.println("Cell Value Of row reveal " + row+ " together with column reveal " + column + " Is " + celtext);    }   System.out.println("--------------------------------------------------");   }  } }

Above instance volition live on executed In IE11 browser near to extract information from spider web table. It volition impress extracted information In console. Next transportation volition exhibit y'all how to configure PhantomJS GhostDriver amongst eclipse to run selenium WebDriver assay instance In It..

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post