Hello,
I am using selenium grid with phantomjs browser. I have problem with open one https page. When i run driver.getTitle() i get empty string. When i use driver.getPageSource() then i get "<html><head></head><body></body></html>"
This is really weird because when i use phantomjs+junit than all works fine. Problem is when i use phantomjs +selenium grid on only this page. For other page phantomjs+selenium grid works fine. I get next error:
org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for visibility of element located by By.id: loginInput
It looks like phantom cannot open only this page but why? What can i do with this?
My code:
Base.java
package testNG.Parallel;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ThreadGuard;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
public class Base {
protected ThreadLocal<RemoteWebDriver> threadDriver;
DesiredCapabilities DesireCaps;
FileWriter plik4;
@BeforeClass
public void setUp() throws IOException {
long start=System.nanoTime();
threadDriver = new ThreadLocal<RemoteWebDriver>();
String[] cli_args = new String[] { "--ignore-ssl-errors=true"};
DesireCaps = DesiredCapabilities.phantomjs();
DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
cli_args);
plik4 = new FileWriter("czasy.txt",true);
DesireCaps
.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"//usr/local/share/phantomjs-1.9.8-linux-x86_64/bin/phantomjs");
DesireCaps.setJavascriptEnabled(true);
threadDriver.set(new RemoteWebDriver(new URL("
http://localhost:4444/wd/hub"), DesireCaps));
long stop=System.nanoTime();
long result=stop-start;
plik4.write(result+ "\n");
plik4.close();
}
public WebDriver getDriver() {
return threadDriver.get();
}
public static FirefoxDriver forceInit() {
try {
return new FirefoxDriver();
} catch (WebDriverException exc) {
return forceInit();
}
}
@AfterClass
public void closeBrowser() {
if(getDriver()!=null)
getDriver().quit();
}
}
And test class:
package testNG.Parallel;
import org.testng.annotations.Test;
import java.io.FileWriter;
import java.io.IOException;
import
org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Clock;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.Helper;
public class AccountTabTime extends Base {
WebDriver driver;
Clock clock;
WebDriverWait _wait;
Helper hp;
ApplicationContext context;
WebElement element;
FileWriter plik;
@Test
public void test() throws IOException, InterruptedException {
driver = getDriver();
driver.manage().window().setSize(new Dimension(1280, 1024));
_wait = new WebDriverWait(driver, 30);
plik = new FileWriter("accountTabTime.txt",true);
context = new ClassPathXmlApplicationContext("file:src/main/resources/Spring.xml");
hp = (Helper) context.getBean("thirdConf");
login();
getTime();
logout();
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public void login() throws InterruptedException {
driver.get( here my https address );
System.out.println(driver.getPageSource() );
new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.id("loginInput")));
driver.findElement(By.id("loginInput")).sendKeys(hp.getLogin());
driver.findElement(By.name("password")).sendKeys(hp.getPassword());
driver.findElement(By.name("form_action")).click();
}
public void logout() {
element = _wait.until(ExpectedConditions.presenceOfElementLocated(By
.linkText("LOGOUT")));
driver.findElement(By.linkText("LOGOUT")).click();
driver.findElement(By.xpath("//button[contains(.,'Logout')]")).click();
driver.close();
driver.quit();
}
public void getTime() throws IOException {
element = _wait.until(ExpectedConditions.presenceOfElementLocated(By
.linkText("My account")));
driver.findElement(By.linkText("My account")).click();
long start = System.currentTimeMillis();
element = _wait.until(ExpectedConditions.elementToBeClickable(By
.xpath("//button[contains(.,'Change')]")));
while (isElementPresent(By
.xpath("//div[contains(.,'Customer's account data')]")) == false
&& isElementPresent(By
.xpath("//div[contains(.,'Customer data')]")) == false) {
}
long stop = System.currentTimeMillis();
long result = stop - start;
plik.write("Time in miliseconds : " + result+"\n");
plik.close();
}
}
Please help me with this. I cannot put web address here cause it is on production env.