phantomjs cannot open url - java

I am not having any luck getting Phantomjs to access a url in my Selenium webdriver tests. I continue to get the following error after the assert -
Expected :Login
Actual :403 - Forbidden: Access is denied.
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at
Here is my - Also HTML Unit Driver does the same thing. However when I use Firefox driver it runs fine.
public class EasyElectPhantomTest {
private WebDriver driver;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private String baseUrl;
#Before
public void setUp() throws Exception {
driver = new PhantomJSDriver();
baseUrl = "https://secure02.pilot.principal.com/";
#Test
public void testEasyElectPhantom() throws Exception {
driver.get(baseUrl + "/login?token=ODEFIJMLEHGIOPRNGIYN");
driver.manage().window().maximize(); //Maximizing window
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
assertEquals("Login", driver.getTitle());
driver.findElement(By.id("firstName")).sendKeys("Ryan");

Related

Unable to drag and drop in selenium for only this website

WebDriver driver = new ChromeDriver(); //Launch the chrome browser
driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[#id=\"todrag\"]/span[2]"));
WebElement from = driver.findElement(By.xpath("//*[#id=\"todrag\"]/span[2]"));
WebElement to = driver.findElement(By.xpath("//*[#id='mydropzone']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(from, to).perform();
I put it in Junit test. Works fine for me.
But I noticed you're not setting property to use a local chromedriver.
Have you got a chromedriver downloaded?
private WebDriver driver;
#Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver",
//"C:/path/to/your/chromedriver.exe"
"/path/to/your/chromedriver"); // Might be this.
driver= new ChromeDriver();
}
#After
public void tearDown() throws Exception {
driver.quit();
}
#Test
public void testDragNDrop() {
driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[#id=\"todrag\"]/span[2]"));
WebElement from = driver.findElement(By.xpath("//*[#id=\"todrag\"]/span[2]"));
WebElement to = driver.findElement(By.xpath("//*[#id='mydropzone']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(from, to).perform();
}

selenium script unable to run

WebDriver driver;
String baseUrl = "http://example.com";
#BeforeClass
public void beforeClass() {
System.setProperty("webdriver.firefox.marionette","local path to geckodriver-v0.10.0-win64");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver();
}
#Test
public void login() throws InterruptedException {
driver.get(baseUrl);
Thread.sleep(3000);
}
#AfterClass
public void afterClass() {
}
this code I am trying to run using TestNG tool but it's failing.
It runs perfectly when using it as Java Application but I want to run this script as a TestNG script

webdriver on safari works well in debug mode, but could not work well when I run it

I test safari browser on Windows with Selenium Webdriver, when in debug mode, my script works well, but when I run it, it could not work well. Does anyone encounter this situation?
public class JustForTestSafari {
public WebDriver driver;
#Test
public void f() {
driver = new SafariDriver();
String baseURL = "http://universitytest.emersonprocess.com/";
String expectedTitle = "ProcessWorld - Your Connection to Global Information";
WebDriverWait wait = new WebDriverWait(driver, 30);
driver.get(baseURL);
driver.manage().window().maximize();
String actulTitle = driver.getTitle();
Assert.assertEquals(expectedTitle, actulTitle);
driver.findElement(By.id("_ctl0_mastercontent_username")).clear();
driver.findElement(By.id("_ctl0_mastercontent_username")).sendKeys("***.guo");
driver.findElement(By.id("_ctl0_mastercontent_password")).clear();
driver.findElement(By.id("_ctl0_mastercontent_password")).sendKeys("*******");
driver.findElement(By.id("_ctl0_mastercontent_btn_standardsignin")).click();
}

Running Selenium Webdriver script in Chrome

I am trying to run Selenium Webdriver script in Chrome, have added following lines in my existing script
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\chromedriver.exe");
private WebDriver driver = new ChromeDriver();
I am building my script in Intellij using Java. Not sure why i am getting "can not resolve symbol setProperty". I tried changing JRE and JDK files but nothing has worked. Any help would be appreciated.
Adding code
public class StartCaseJava extends TestCase {
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
// Getting Date and Timestamp for Last Name
Date d = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("MMddyyHHmmss");
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\\chromedriver.exe");
// private WebDriver driver = new ChromeDriver();
// driver = new FirefoxDriver();
// driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
private WebDriver driver = new ChromeDriver();
public void testStartCaseJava() throws Exception {
// System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
It's a long shot but should this
C:\Users\Garimaari\IdeaProjects\Webdriver testing\Chromedriver\chromedriver.exe")
maybe be renamed to C:\Users\Garimaari\IdeaProjects\Webdriver testing\Chromedriver\chromedriver.exe")
or are the double back slashes actually a necessary feature?
This might be because of one missing '\' before chromedriver.exe in your setProperty string.
Try using :
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Garimaari\\IdeaProjects\\Webdriver testing\\Chromedriver\\chromedriver.exe");
I am able to run my script using Chrome now. Here is the small sample declaration I used:
class StartCaseJAva {
static WebDriver driver;
public void testcasejava()) {
System.setProperty(path);
driver = new ChromeDriver();
}
}

Can I open 2 Firefox Drivers on 2 Screens?

I am running tests using two Firefox Drivers to display the results. I am using two screens on my computer. Can I automatically open a driver on each screen via java code running in Eclipse?
Thanks.
I think you should run parallel test cases https://saucelabs.com/java/se2/8
#RunWith(Parallelized.class)
public class WebDriverParallelTest {
private String browser;
private String os;
private String version;
public WebDriverParallelTest(String os, String version, String browser) {
super();
this.os = os;
this.version = version;
this.browser = browser;
}
#Parameterized.Parameters
public static LinkedList browsersStrings() throws Exception {
LinkedList browsers = new LinkedList();
browsers.add(new String[]{Platform.XP.toString(), "17", "firefox"});
//add any additional browsers here
return browsers;
}
private WebDriver driver;
#Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
capabilities.setCapability(CapabilityType.VERSION, version);
capabilities.setCapability(CapabilityType.PLATFORM, os);
this.driver = new RemoteWebDriver(
new URL("http://credential of sauce lab"), capabilities);
}
#Test
public void webDriver() throws Exception {
driver.get("http://www.amazon.com/");
assertEquals("Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", driver.getTitle());
}
#After
public void tearDown() throws Exception {
driver.quit();
}
}

Categories