I have some selenium tests that work great in Chrome (locally and remotely) but when I run them remotely from my machine to a Windows 2012 VM they can't find any elements AFTER clicking a button to move to the next web page.
Here is a code snippet:
DesiredCapabilities caps = null;
caps = DesiredCapabilities.internetExplorer();
caps.setBrowserName("internet explorer");
caps.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
caps.setJavascriptEnabled(true);
caps.setPlatform(Platform.WIN8);
String nodeURL = "http://0.0.0.0:5555/wd/hub"
driver = new RemoteWebDriver(new URL(nodeURL), caps);
// IE launches correctly, goes the cart page. Calculations are done on the pricing, and we click to move to the login page
driver.findElement(By.id("userName")).sendKeys("test#test.com");
// ^^ NoSuchElementException: Unable to find element with id == userName
So obviously there is a good connection made. Actions are performed and my tests move from the cart page to the login page. I even added a wait.until, hoping that it was a timing issue, but it timed out after 15 seconds. I'm watching the driver on RDP, it moved to the page. During the 15 seconds, I even opened the dev tools and checked to see if the element was there and it was.
What's going on? Thanks!
Preface: As a QA automation engineer, I hate IE.
It turns out that http://company.com was added a trusted site, but not https://company.com. Once I added that, it started working.
Did I mention I hate IE?
Related
First of all, I need to state that I am total beginner with Selenium.
I am trying to test an application in firefox browser using Selenium. Due to security issues the application works only over vpn.
My problem occurs with the following steps; I create the webdriver and navigate to the start (login) page of application. I get an "Authorization request" popup. If I cancel the popup, then I get to a page that states "Connection is not secure" (it's https address). After I get passed that, I lose the part where Selenium program should populate username and password and it just stays on the login page.
My question, is there a way to start Selenium testing on an application so that it is already opened and prepared (ie logged in) in browser? I am not happy that username and password are hard-coded in Selenium code.
If that is not possible, how do I skip that authorization popup and problem with non-secure connection? How do I populate username and password in safest way?
Thanks!
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium-java-3.0.1\\geckodriver.exe");
// I tried also with this code bellow in comment, but it did not work, it did not even get to login page
//WebDriverWait wait = new WebDriverWait(driver, 10);
//Alert alert = wait.until(ExpectedConditions.alertIsPresent());
//alert.authenticateUsing(new UserAndPassword("cfadmin", "20lipim18"));
driver.get("https://Application_login_page.com");
driver.findElement(By.xpath(".//*[#id='login']")).click();
driver.findElement(By.xpath("[#id='login']")).sendKeys("Username");
}
if it's possible, is there a way to start Selenium testing on application that is already opened and prepared (logged) in browser?
Try using firefox profile. Since selenium open fresh instance of browser by default. You can use your own firefox frofile.
This is a code to implement a profile, which can be embedded in the selenium code.
ProfilesIni profile = new ProfilesIni();
// this will create an object for the Firefox profile
FirefoxProfile myprofile = profile.getProfile("default");
// this will Initialize the Firefox driver
WebDriver driver = new FirefoxDriver(myprofile)
It will also maintain the session means you are already login to the application in firefox(default profile). Then if you execute the script, you will see that you are already logged in to the application.
There is no way to open already authorised page, you have to have to pass username and password through selenium script.
You may use below code to do the authentication
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(username, password));
I'm trying to use PhantomJS 2.0/GhostDriver instead the ChromeDriver, since I have read I could speed up my UI tests.
This is the test code I'm running, as part of a Junit test:
#Override
public void runTestCase() throws Exception {
long startTime = System.currentTimeMillis();
// log in as admin
Login.loginAs("admin", "password");
System.out.println(System.currentTimeMillis() - startTime);
}
The loginAs function fills in the text fields for the username and password, then click on the submit button and finally moves in the home section of the new returned page.
Now, I'm running once a time this simple test using both Phantomjs and ChromeDriver as driver for Selenium in Java (v2.45).
They are initialized as follow:
ChromeDriver
System.setProperty("webdriver.chrome.logfile", workingDirectory + "\\chromedriver.log");
service = new ChromeDriverService.Builder().usingDriverExecutable(new File(workingDirectory + "\\chromedriver.exe")).build();
capabilities = DesiredCapabilities.chrome();
options = new ChromeOptions();
options.addArguments("--allow-file-access-from-files");
options.addArguments("--verbose");
capabilities.setVersion("");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(service, capabilities);
PhantomJS
System.setProperty("phantomjs.binary.path", workingDirectory + "\\phantomjs.exe");
cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
cliArgsCap.add("--webdriver-loglevel=INFO");
cliArgsCap.add("--load-images=false");
capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
driver = new PhantomJSDriver(capabilities);
I'm running my test on a 64bit Windows 7 machine. So, having a look the time took by the test, I always note that ChromeDriver is faster than PhantomJS. Always. For instance, if the test with ChromeDriver takes about 3-4 seconds, the same with PhantomJS takes about 5-6 seconds.
Has anyone experienced with this issue? Or could anyone give me any reason for that? Am I setting something wrong?
Furthermore, if you need more details, let me know.
I have found that this setting uses a lot of memory that seems to keep growing:
cliArgsCap.add("--load-images=false");
But when I use this setting the memory usage is stable:
cliArgsCap.add("--load-images=true");
"PhantomJS is a headless WebKit scriptable with a JavaScript API" as it's explained on the main page of the project.
Google split from WebKit to create Blink to use it in Chrome.
What are the main differences between them - unfortunately I'm not the expert here.
I run one of my really long scenarios both on Chrome and PhantomJS and to my surprise the difference was pretty significant:
PhantomJS - 583.251 s
Chrome - 448.384 s
Using PhantomJS doesn't bring performance benefits in my case but running tests headless does. I can use machine without graphical desktop and save computing power for some additional threads.
The slowest aspect of a web page is the downloading of html, JavaScript, css, images, etc and making AJAX request.
To anybody who says Headless is faster, how can headless address any of these?
I'm writing a Java app in which I'm doing a simple driver.get(url) in which the url will prompt for a cert selection. I want to try and automate the cert selection process in Firefox 33 using the AutoIt jar, but I can't even get my Java program to continue after it executes this get, since the site is in an indefinite state of loading until a cert is selected, so the execution indefinitely stays on the get itself. Is there any way around this?
I found a similar question: Make Selenium Webdriver Stop Loading the page if the desired element is already loaded?
Ths solution given in the above link is to change the firefox settings in case the webpage is taking too long to load.
FirefoxBinary firefox = new FirefoxBinary(new File("/path/to/firefox.exe"));
FirefoxProfile customProfile = new FirefoxProfile();
customProfile.setPreference("network.http.connection-timeout", 10);
customProfile.setPreference("network.http.connection-retry-timeout", 10);
driver = new FirefoxDriver(firefox, customProfile);
I have a selenium test failing on Sauce Labs due to a stale element. The test opens up a page, clicks on a few links within the site, click on a link that takes you to Facebook, then back and that's where things stop working. For some reason after coming back to the original page, the driver is no longer able to find "fresh" elements. This seem to be only happening when using Android on Sauce Labs. The code is below, please let me know if you have any suggestions for how to work around it (I don't care if it is perfect at this point, just want to get it working).
#Test
public void testFooter() throws Exception {
driver.get(baseUrl + "/");
// these links are all on my domain, work just fine
driver.findElement(linkText("About Us")).click();
driver.findElement(linkText("Press")).click();
driver.findElement(linkText("Careers")).click();
driver.findElement(linkText("FAQ")).click();
driver.findElement(linkText("Industry Resources")).click();
driver.findElement(linkText("Share")).click();
// going out to facebook works
driver.findElement(linkText("Facebook")).click();
driver.navigate().back();
// coming back to the page and clicking the twitter link fails due to
// org.openqa.selenium.StaleElementReferenceException: WebElement is stale.
driver.findElement(linkText("Twitter")).click();
driver.navigate().back();
}
This is my first question on Stack Overflow. Thanks to all StackOverflow users who keeps technology passion ticking.
I am testing a web application with selenium Webdriver . It is payment webpage where, after selecting Payment method as 'PayPal' it opens up a new Popup , a PayPal popup and i Switch window to Paypal , do all my necessary Transaction. And once the Transaction is successful , automatically the paypal popup is closed, and i am not able to return to my original window from where i have initiated transaction.
I am getting following error in eclipse console:
Starting ChromeDriver (v2.9.248315) on port 25947
[70.164][SEVERE]: Unable to receive message from renderer
The following details might help :
selenium Webdriver (2.28.0)
java - JRE7
Google Chrome Version - Version 33.0.1750.146
Test Framework - Test NG
Here is my code :
// To Switch to Popup/Paypal window
String currentWindowHandle=driver.getWindowHandle();
Set<String> openWindowsList=driver.getWindowHandles();
String popUpWindowHandle=null;
for(String windowHandle:openWindowsList)
{
if (!windowHandle.equals(currentWindowHandle))
popUpWindowHandle=windowHandle;
}
driver.switchTo().window(popUpWindowHandle);
// Carraying out my paypal transaction
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[#id='loadLogin']")).click();
Thread.sleep(8000);
WebElement login_email = driver.findElement(By.xpath("//*[#id='login_email']"));
login_email.clear();
login_email.sendKeys(Keys.BACK_SPACE);
login_email.sendKeys("abc#abc.com");
WebElement login_password = driver.findElement(By.xpath("//*[#id='login_password']"));
login_password.clear();
login_password.sendKeys("abcxyz");
// Next Click is Final Click on PayPal
driver.findElement(By.xpath("//*[#id='submitLogin']")).click();
// Transaction is finished on PayPal side and it automatically popup is closed
//Now i am trying to switch to my last working(original) window
driver.switchTo().window("My Web Page Title");
You should be using:
driver.switchTo().window(currentWindowHandle);
It causes because page took long time to load , you need add additional line to your chromedriver option.
System.setProperty("webdriver.chrome.driver","E:\\selenium\\chromedriver_2.41\\chromedriver.exe");
//mention the below chrome option to solve timeout exception issue
ChromeOptions options = new ChromeOptions();
options.setPageLoadStrategy(PageLoadStrategy.NONE);
// Instantiate the chrome driver
driver = new ChromeDriver(options);
The problem is resolved.
The place where I was declaring currentWindowHandle was after clicking and it takes the new window as the Current Window handle.
I just moved below statement to before the new window click event.
String currentWindowHandle=driver.getWindowHandle();
Thanks all for your time and Help.