I am new to Capybara so I may miss something obvious but I am not sure what is going on. I have three test cases in the same suite with app_host set to URL A.
Test1: Visit website A which then redirects to website B and requires log in to B.
Test2: Visit website B and perform some tests
Test3: Visit website B and perform some tests.
In test 2 and 3, I use visit with absolute URL to visit website B and the code is identical. In test 2, I don't have to log in but in test 3, website B redirects to the log in page.
I found a similar issue here: Capybara with headless chrome doesn't clear session between test cases which use different subdomains but after updating from 2.8 to 3.9, I still have the same issue.
I also tried to Capybara.reset_sessions! and Capybara.current_session.driver.browser.manage.delete_all_cookies after each test without success.
I am using Capybara 3.29.0 and Selenium-webdriver 3.142.6. The Chrome driver is in a docker image selenium/standalone-chrome:3.14.0-iron.
Driver registration:
Capybara.register_driver :selenium do |app|
chrome_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeoptions: {
args: %w[headless no-sandbox disable-gpu --window-size=1024,1024]
})
Capybara::Selenium::Driver.new(app,
browser: :remote,
:url => 'http://localhost:4444/wd/hub',
:desired_capabilities => chrome_capabilities)
end
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
Any idea what cause the difference in behavior?
You're using massively out of date versions of Capybara and selenium-webdriver. The WebDriver protocol only allows for resetting the cookies of the host you're on when reset occurs, so if you're moving between hosts the cookies for only one of them are going to get cleared. If, however, you switch to using a recent version of Capybara with a recent version of selenium-webdriver and Chrome then Capybara will clear cookies for all hosts (using CDP)
Related
I cannot assert any text with the following configuration and screenshots are blank, even though there are no errors and network activity shows 100% success.
Versions
phantomjs-prebuilt 2.1.12
phantomjs 2.1.1
poltergeist 1.13.0
capybara 2.12.0
Debug logs
Gist of phantomjs/poltergeist/capybara logs
Symptoms
captured screenshot and it is transparent
captured network activity (see gist) successful
captured html is good (see gist)
no errors in phantomjs debug (see gist)
no errors in poltergeist debug (see gist)
neither long sleeps nor high Capybara.default_max_wait_time have no impact on result
react js works with both manual testing and with selenium/chrome
Feature
Feature: smoke
Scenario: Home
Given I go to the home page
#When I sleep for 30 seconds
Then I should see "Landing Page"
Poltergeist setup
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {
js_errors: true,
timeout: 180,
debug: true,
phantomjs: "#{Rails.root}/node_modules/phantomjs-prebuilt/bin/phantomjs",
phantomjs_options: %w(--debug=true --load-images=no --proxy-type=none --ignore-ssl-errors=yes --ssl-protocol=TLSv1),
window_size: [1280, 600],
# inspector: true,
phantomjs_logger: PoltergeistLogger # File.open("target/phantomjs.log", "a")
})
end
TLDR;
I have no errors yet a reactjs page doesn't seem to be rendering a DOM within phantomjs or when accessed via poltergeist.
I've run out of options that I'm aware of. Any thoughts I can try?
Unable to open firefox browser with specified url in selenium webdriver. Only the browser is opening without the url.
Firefox version is 47.
Selenium version is 2.53.
There are two ways to solve your problem.
1- You can downgrade your firefox by reinstalling and select Never check for updates (not recommended: security risk) in your firefox by nevigate through
Open Menu->Options->Advanced.
2- if you want to working with current version of firefox which is 47 you should try with MarionetteDriver...by following this
If you have any problem with this let me know...:)
I'm writing a suite of Protractor tests from the ground up for a new Angular webapp. My team has asked me to run my tests against their Test server instance. I've got my config file and a basic test spec set up, but as soon as I hit the main page and do a simple expect() statement, I get "Timed out waiting for Protractor to synchronize with the page after 11 seconds."
Here's my test:
describe('the home page', function() {
it('should display the correct user name', function(){
expect(element(by.binding('user.name')).getText()).toContain(browser.params.login.user);
});
});
I cloned the dev team's git repo, set it up on my localhost, changed my baseUrl and ran my Protractor test against it locally. Passed without a hitch.
After some conversation with the dev team, I've determined that it's not a $http or $timeout issue. We use both of those services, but not repeatedly (I don't think they're "polling"). None of them should happen more than once, and all the timeouts are a half-second long.
What else could cause Protractor to time out like that? I wish it failed on my localhost so I could go tweak the code until I find out what's causing the problem, but it doesn't.
I have discovered the solution: check for console errors.
Turns out, one of our $http requests wasn't coming back because my Protractor tests were accessing the page via https, but one of our xhtml endpoints was at a non-secured location. This resulted in a very helpful console error which I had not yet seen, because it only occurred when accessing the site with WebDriver.
The error text: "The page at [url] was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint. This request has been blocked; the content must be served over HTTPS."
I modified my baseUrl to access the site via regular http, and now everything is working fine.
I am testing a web app with loads and loads of web pages and I would like to verify that none of the URLs are broken on every commit. Here is a code snippet.
$page = $this->getSession()->getPage();
$page_URLs = $page->findAll('css', 'header nav ul a');
assertEquals(16, count($page_URLs));
foreach($page_URLs as $pageUrl){
try{
$pageUrl->click();
$statusCode = $this->getSession()->getStatusCode();
echo $pageUrl->getText();
assertEquals(200, $statusCode, "The webpage is not available");
} catch (Exception $ex) {
echo 'Caught exception: ', $ex->getMessage(), "\n";
}
$this->getSession()->back();
}
I was using the Behat, MINK with Goutte driver (as a headless browser) for CI integration (and getStatusCode() was working fine). But most of the functionality on the web app is java script driven therefore I have to move on to PhantomJS which support javascript. But I didn't realise that getStatusCode() doesn't work with PhantomJS.
Has anyone got any idea if I can replace this with something and get the similar result.
PhantomJS support in Behat is realised via the WebDriver protocol (selenium). WebDriver doesn't support inspecting status codes on purpose, as it falls out of scope of emulating user actions.
I am using protractor along with PhantomJs for e2e testing of my angular app.
Currently I am testing a login form. All the test work fine when I am simply checking
whether the form loaded correctly
username/password fields are empty
errors are displayed when you enter incorrect authentication information.
So far phantomJs and protractor have been quiet cooperative
However the below mentioned test cases simply fails all the time in protractor. I have tried various permutation and combinations but to no avail.
when the user enters correct authentication information in the login form, the angular app will change the route to dashboard section. i.e the url in the browser window would change from
http://localhost:12345/#/signin/
to
http://localhost:12345/#/dashboard
When I run the below give test, I know that the authentication was successful because the server logs display a success response object sent. Upon receiving this response, the angular app should have changed the route to /dashboard. However protractor fails to capture this change in route.
My test looks like below:
describe("SignOn Page - Performing authentication with valid credentials ",function(){
var ptor;
beforeEach(function(){
ptor = protractor.getInstance();
ptor.get('#/signon');
ptor.findElement(protractor.By.id('username')).sendKeys('joe');
ptor.findElement(protractor.By.id('password')).sendKeys('pass');
element(by.partialButtonText('Sign In')).click();
ptor.waitForAngular();
});
it("should re-direct user to dashboard page once the user enters correct authentication information",function(){
ptor = protractor.getInstance();
expect(ptor.getCurrentUrl()).toContain('dashboard');
expect(ptor.getTitle()).toContain('dashboard');
});
});
My question to this forum is, does protractor have issues changing states ? I am using ui.router in my angular application ?
I had the same issue because I was using phantomJS 1.9.x and not the 2.x
So you need to uninstall phantomjs 1.9
npm remove -g phantomjs
and install phantomJS 2.x
npm install -g phantomjs2
Hope it's also solve your issue