I've been using Selenium 2/WebDriver through Ruby 1.9.2, and directly through FireFox it works fine. I wanted to use HtmlUnit so it's faster and headless, so I'm trying selenium-server-standalone-2.17.0 as it should in theory require no code changes, and also I want to start using Java/groovy with HtmlUnit.
The problem is that half the time or more, a test fails because when I click a button and switch windows, the HTML (and title) in the new window is the same as the old one.
I added lots of debugging output to my function to try to narrow it down:
def switch_to_newest_window()
assert(#driver.window_handles.size > 1, "only one window")
print "switch to newest window, handles=#{#driver.window_handles}...\n"
print "current handle: #{#driver.window_handle}\n"
print "#{#driver.window_handles[0]}\n"
print "#{#driver.window_handles[-1]}\n"
print "title: #{#driver.title}\n"
save_file("first.html", #driver.page_source)
#driver.switch_to.window(#driver.window_handles[-1])
print "new handle: #{#driver.window_handle}\n"
print "new window title: #{#driver.title}\n"
save_file("second.html", #driver.page_source)
end
And the relevant output is:
switch to newest window, handles=["36543124", "1755893858"]...
current handle: 1755893858
36543124
1755893858
title: Create FlowSet
new handle: 1755893858
new window title: Create FlowSet
So it's correctly switching windows, but the HTML is the same! If you diff first.html and second.html, there is no output.
I'm also a ruby noob so I may well be doing things the hard/slow way or incorrectly.
Other details:
running on Windows 7.
Selenium Server server-standalone-2.17.0
Server output when starting HtmlUnit session:
13:03:12.292 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=true, cssSelectorsEnabled=false, browserName=htmlunit, nativeEvents=false, rotatable=false, takesScreenshot=false, version=}] at URL: /session)
Thanks very much in advance for any help.
Joel
Related
I've tried to maximize the window onPreapre by the command below:
browser.driver.manage().window().maximize();
But it doesn't maxmize the window and there's no error on selenium webdriver logs, actually it seems like the execute has been succeed -
Starting ChromeDriver 2.26.436421 (6c1a3ab469ad86fd49c8d97ede4a6b96a49ca5f6) on port 5814
Only local connections are allowed.
17:14:28.898 INFO - Done: [new session: Capabilities [{count=1, browserName=chrome, chromeOptions={args=[--no-sandbox, --test-type, --memory-metrics, --console, --crash-on-failure], prefs={download={directory_upgrade=true, default_directory=./Users/Idan/automation/tests/downloaded/, prompt_for_download=false}}}}]]
17:14:28.909 INFO - Executing: [set script timeout: 90000])
17:14:28.910 INFO - Done: [set script timeout: 90000]
17:14:28.969 INFO - Executing: [maximise window])
17:14:29.236 INFO - Done: [maximise window]
17:14:29.244 INFO - Executing: [maximise window])
17:14:29.250 INFO - Done: [maximise window]
You can try it with start-maximized flag:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['start-maximized']
}
}
I remember we had a similar issue - what we did is first set the size of the window and then maximize - don't remember exactly why did we apply this workaround, but it works for us:
browser.manage().window().setSize(1400, 900);
browser.manage().window().maximize();
According to your log - you do maximization twice. Maybe the first time it is maximized, and after the second try it is restored down to default size
You can use javascript to do this.
((IJavaScriptExecutor)browser).ExecuteScript("window.resizeTo(x, y);");
'x' and 'y' depends on your screen resolution.
The best way to maximize a chrome app is through JavaScript. Try this:
//Maximizing Chrome App Window.
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("window.resizeTo(1366, 768);");
Change the parameters 1366, 768 according to your monitor settings/setup.
I had the same problem with our browser.manage().window().setSize(1024, 768);, but when I used a better ratio it worked fine browser.manage().window().setSize(1200, 800);
Not sure this will help anyone but hope it does.
Were facing the same kind of problem and solved using this snippet: (Java)
driver.manage().window().fullscreen();
**Screen goes in the fullscreen mode, and you will not be able to see the address bar, all you will see is the content of the page.
I'm using Protractor on Selenium, MacOS and Chrome.
I'm trying to run the same test using an array of elements to provide the test data:
As I read here: Looping on a protractor test with parameters
I was trying that solution but when I run it, my test is not even found:
for(var i = 0; casos.length; i++){
(function(cotizacion){
it('obtener $1,230.00 de la cotizacion', function(){
browser.get('https://mifel-danielarias.c9users.io');
login(user,pass);
fillVidaCotizadorForm(formData);
//browser.sleep(5000);
var primaTotal = element(by.binding('vida.primaTotal'));
browser.wait(EC.visibilityOf(primaTotal),4000);
expect(primaTotal.getText()).toBe(cotizacion);
});
})(casos[i].Fallecimiento);
}
Output message:
> [14:13:01] I/hosted - Using the selenium server at
> http://localhost:4444/wd/hub [14:13:01] I/launcher - Running 1
> instances of WebDriver Started
>
>
> No specs found Finished in 0.003 seconds
This loop is inside my describe function and if I run the test normally without any loop, it runs flawlessly.
As #OptimWorks mentioned in his comment, Data Driven Approach was exactly what I was looking for, and this question provided several good answers.
I am attempting to run automated selenium headless tests, and I'm running into the issue where the tests hang for some inexplicable reason. The full snippet is on pastebin, but the relevant portion of the code is reproduced below:
# stress testing
i = 0
while True:
print i
d = webdriver.Remote(
service.service_url,
desired_capabilities=DesiredCapabilities.CHROME
)
print i, "started driver"
d.get("http://www.facebook.com")
print i, "got fb"
d.quit()
print i, "quit"
i += 1
Sample output is
0
0 started driver
0 got fb
0 quit
...
11 <hang>
Which indicates that webdriver.Remote is refusing to properly initiate the driver. This also occurs when the driver instance is constructed directly with webdriver.Chrome (instead of running the ChromeDriver as a service).
After sending SIGINT to the hanging program, I get a stacktrace (pastebin) indicating a blocking socket read somewhere in the constructor.
ChromeDriver's log (dropcanvas) doesn't seem to indicate anything amiss, and I'm quite puzzled as to what is happening here.
Similar questions have been asked previously, the most relevant being Selenium Chromedriver Hangs?; however, I cannot reproduce the accepted solution (starting Xvfb anew for each instantiation of webdriver...). Here, the equivalent would be calling Xvfb.start immediately preceding d = webdriver.Remote... and calling Xvfb.stop at the end of the loop; I have tried this to no success.
Any help would be greatly appreciated.
Edit: As indicated by the stacktrace, webdriver.Remote was hanging on some socket read function; I traced the request to be
POST 'http://127.0.0.1:<chromedriver_port>/session'
with body
'{"desiredCapabilities": {"platform": "ANY", "browserName": "chrome", "version": "", "javascriptEnabled": true}}'
So it seems like ChromeDriver isn't responding for some reason. Will continue debugging.
Selenium Select Window command fails and shows "Could not find window with title....". but if i Execute the Select Window command alone it passes the case and verifying the elements.
Code i used:
public void testDefaultlogo() throws Exception {
selenium.open("http://Sitename/samp.aspx");
selenium.type("ctl00_mainContentPlaceHolder_txt_LoginName", "uname");
selenium.type("ctl00_mainContentPlaceHolder_txt_Password", "pwd#12");
selenium.click("ctl00_mainContentPlaceHolder_btn_login");
selenium.waitForPageToLoad("60000");
selenium.click("ctl00_defaultLogo");
selenium.selectWindow("Sample~Window-ID");
verifyEquals("http://Sitename/index.html", selenium.getLocation());
selenium.close();
selenium.selectWindow ("null");
verifyTrue(selenium.isElementPresent("ctl00_defaultLogo"));
I mean by clicking one by one of the follwing commands in Selenium IDE it shows green but if i run the case it failed and shows as i mentioned above
What I can get from your code is that, clicking the "ctl00_defaultLogo" will popup another window. The possible issue could be that after write the command selenium.click("ctl00_defaultLogo") you need to wait for the popup to load.
The possible resolution, insert the command
selenium.WaitForPopUp("Sample~Window-ID", "5000");
before the
selenium.selectWindow("Sample~Window-ID");
This will cause selenium to wait for 5 secs before selecting the popup window.
Hope this helps!!!
some times it may not work for that u better use.
open_window("URL","WindowID or title or name");
selenium.selectWindow("WindowID or title or name");
I'm trying to run a basic test in Internet Explorer via Selenium-RC/PHPUnit, and it always returns with
# phpunit c:\googletest.php
PHPUnit 3.4.15 by Sebastian Bergmann.
E
Time: 35 seconds, Memory: 4.75Mb
There was 1 error:
1) Example::testMyTestCase
PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete()
.
Timed out after 30000ms.
C:\googletest.php:17
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Paul#PAUL-TS-LAPTOP C:\xampp
#
The last command in command history is waitForPageToLoad(30000). The same test runs fine and completes in firefox. How can I get this test to run and complete in internet explorer?
Thanks
There's an open bug in selenium that causes waitForPageToLoad to sometimes timeout on IE.
http://jira.openqa.org/browse/SRC-552
It's marked as occurring on IE6, but I'm experiencing the same error in at least IE9.
A workaround is to wait for e.g. a specific DOM-element on the page that is loading instead of using waitForPageToLoad. For example: waitForVisible('css=#header')
Try going into Internet Options and turn off Protected mode under the security tab. You may also want to decrease the security level for the Internet zone.
I've turned off protected mode and looks like it helped.
If it is acceptable to customize the client driver, here is the Python implementation for your refernece:
def open(self):
timeout = self.get_eval('this.defaultTimeout')
self.set_timeout(0)
self.do_command("open", [url,ignoreResponseCode])
self.set_timeout(timeout)
self.wait_for_page_to_load(timeout)
def wait_for_page_to_load(self,timeout):
# self.do_command("waitForPageToLoad", [timeout,])
import time
end = time.time() + int(float(timeout) / 1000)
while time.time() < end:
if self.get_eval('window.document.readyState') == 'complete': return
time.sleep(2)
raise Exception('Time out after %sms' % timeout)
I just use DOM attribute document.readyState to determine if the page is fully loaded.
IE 9+ intermittently throws a timeout error even the page is fully loaded, for more details.