How to run test cases in headless mode using Phantom JS

0 votes
How to run test cases in headless mode using Phantom JS?
Aug 14, 2019 in Selenium by Bhanu
1,603 views

1 answer to this question.

0 votes

Hi Bhanu, you can run test cases in headless mode using Phantom JS by following this piece of code:

import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;

public class WebDriverBase {

  static protected WebDriver driver;

  public static void setup() {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "src/test/resources/phantomjs");

    driver = new PhantomJSDriver(caps);
  }
  public static void main(String[] args) {
    WebDriverBase.setup();
    driver.get("https://www.facebook.com");
  }
}

You will also need the ghost driver dependency as well:

<dependency>
    <groupId>com.github.detro.ghostdriver</groupId>
    <artifactId>phantomjsdriver</artifactId>
    <version>1.0.1</version>
</dependency>
answered Aug 14, 2019 by Abha
• 28,140 points

Related Questions In Selenium

0 votes
1 answer

How to run Selenium test cases in Headless Chrome browser?

@Afreen to run selenium test cases in ...READ MORE

answered May 17, 2019 in Selenium by Kushal
4,168 views
0 votes
2 answers

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

You first need to download chrome driver ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,140 points
2,010 views
0 votes
0 answers

How to configure ChromeDriver to initiate the browser in the Headless mode using Selenium?

I'm currently working on a Python script ...READ MORE

Apr 2, 2019 in Selenium by Surya
• 970 points
1,825 views
0 votes
1 answer

How to run test scripts in Selenium using PhantomJS?

Hey @Shushil, you can run your test ...READ MORE

answered May 17, 2019 in Selenium by Abha
• 28,140 points
1,759 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,763 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,184 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,258 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,895 views
0 votes
1 answer
0 votes
1 answer

How to run a group of test cases using TestNG in Selenium Webdriver?

Hey Kajal, TestNG allows you to perform ordered ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 28,140 points
2,939 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP