I had been using Cucumber and WebDriver for a while, just adding Spring Boot for dependency injection. The WebDriver was injected by Spring. The first scenario worked fine, but the second scenario got:
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
I did not use any Cucumber Hook to explicitly close/quit the driver, yet the browser closed after the first and second scenario failed.
Related
In Capybara, How can I reuse existing browser to continue run step next. Instead of star a new session and open a new windown and next run a ton of step before.
For example :
First:
session = Capybara::Session.new(:headless_chrome, Capybara.app)
session.open(url)
session.click(...)
sesion.quit()
Second Time:
session = ...#retry the first session state
sesion.do_something()
Capybara is designed as a testing tool, where you want every test to be completely independent of other tests. Because of that it has no support for storing/reloading a session, and uses a fresh browser instance (data-dir, etc) for each session. To prevent creation of a completely new browser setup every time you create a new session you could pass your own --user-data-dir=<some_directory> option when registering your Capybara driver, but it's not Capybara supported usage (and would really not be a good idea if you're actually doing testing rather than web scraping). Another option if all you really want is the cookies retained would be something like https://github.com/kyamaguchi/capybara-sessionkeeper (again bad idea if you're testing since it couples tests to each other).
I have been developing JUnit tests using Selenium webdriver and I test them on BrowserStack.
It works when:
I keep all my selenium scripts in one test method.
I keep my scripts in different JUnit test methods, as they open their own sessions and run smoothly.
I now want each of my Test methods to use the same BrowserStack session (to reduce total run time). Is this possible? I have read somewhere about intern framework a little, but do we have any other simple way to achieve this?
In selenium with java we declare/initialize variable like
WebDriver driver = new FirefoxDriver();
with ruby
driver = Selenium::WebDriver.for :firefox.
So can any one tell me how can we declare/initialize driver in protractor?
I have seen on protractor website, we need to use capabilities but didn't get how a driver is declared.
Actually there is not need to initialize driver in protractor. It is globally available as browser. So in test class you can directly call it as
browser.get(url);
browser.findElement(by.css('cssSelector));
For non-angular pages you can use browser.driver instead of browser. It will look like this
browser.driver.findElement(by.css('cssSelector));
Please read it properly, it will clear your all basic doubts about Protractor. https://angular.github.io/protractor/#/tutorial
I am testing AngularJS app and very new to protractor. Every time I open the browser, it gets opened and then waits for the timeout before throwing the following error on cmd.
Timed out waiting for Protractor to synchronize with the page after 50001ms
I have tried increasing the timeout limit, but always get this error.
I have also tried using all of these:
browser.ignoreSynchronization = true;
browser.driver.sleep(5000);
browser.debugger();
browser.waitForAngular();
The page loads properly and if I use Eclipse and Selenium to interact with button objects, it just works fine.
Only protractor is having Sync issues. Please Help.
Possible reasons why Protractor would time out:
Your web page doesn't implement Angular in an expected way (i.e. with an ng-app on the body tag). More often, the error you will get in this case is Angular not found on page, but a timeout isn't out of the question. Using ignoreSynchronization would fix this if it were the issue, so this one isn't you.
An HTTP request is pending or fails. Open up your dev console and check the "Network" tab when the page loads with Protractor (it may happen with Protractor and not in a manual test). If you find something failing, make sure you are issuing the request correctly. For example, if you're trying to access an HTTP endpoint through HTTPS, it's definitely possible that the request would fail and Protractor would time out.
Your page is polling $timeout or $http repeatedly. Protractor won't do anything until Angular has reached a "resting" state (all elements and data bindings are loaded and all requests have returned).
The official list of timeout reasons is here: https://github.com/angular/protractor/blob/master/docs/timeouts.md.
But if you check the Javascript console and Network requests as the page loads, you should be able to figure out what's wrong. Good luck!
when i'm using selenium rc i used waitForPageToLoad method but in WebDriver i'm unable to find method for wait. is there any way to achieve this? i know webDriver allows wait For page Load implicitly but it's not working for me. thanks in advance.
WebDriver shouldn't return until the page has loaded, but if this is not working for you e.g. your pages is using AJAX, then you could add your own wait code using wait.until from org.openqa.selenium.support.ui.WebDriverWait.
There's a full example at http://www.qaautomation.net/?p=263