django liveservertestcase error - django-testing

I am trying to run django tests in my app.
My app is "accounts" and after I run the tests using the command
"python manage.py test accounts "
it creates a test database which is apt. So the default port for testing is localhost:8081. But then when tests go the login function with the url "locahost:8081/accounts/login" I don't see the login page and it shows a blank page. I get the error saying
NoSuchElementException: Message: u'Unable to locate element: {"method":"id","selector":"id_username"}' ; Stacktrace: Method FirefoxDriver.prototype.findElementInternal_ threw an error in file:///tmp/tmpfJYYIZ/extensions/fxdriver#googlecode.com/components/driver_component.js
So I think it couldn't load the login page and so it didn't find the id_username(This is the id for text box in login page).
I thought may be it couldn't load the "localhost:8081" so i added it to the django_site database table in setUpClass of the tests.py . But still it didn't work.
I also tried adding the "localhost:8081" in fixtures and include it in tests.py .It didn't help either.
Any ideas please.??

Related

Blank page in page with CRA, NX.dev and vercel deployment

I am working on an application with React on monorepos, using nx.dev, service workers and configured with craco (came by default when using cra-to-nx). In addition, I'm deploying my application in vercel.
The problem comes in that when entering my application, always appears a blank screen, and by console appears the following error:
Error by console 404 static
If I enter in that file main.XXX.js, I see the following:
Error by console 2
I have tried several of the solutions I have found on the internet, but nothing has worked.
I have written
I have tried with homepage=".", homepage="/" and homepage="mydomain.com" in the package.json.
Thank you very much in advance

Failing authentication test, using Laravel, phpunit and Homestead

So, I'm trying to test the register and login features on a Laravel 5.8 project, running on Homestead.
My problem is that I can't get the tests (for login and for register) to pass the assertAuthenticated() and assertAuthenticatedAs() functions.
I created the login feature using php artisan make:auth and didn't changed a lot, just created a "username" field to use instead of email.
When I test things like assertStatus(), $this->get(url), everything works fine but when I add the line $this->assertAuthenticatedAs($user) for example, the test crashes.
This is my actual passing function:
public function test_login_valid_user()
{
$user = factory(User::class)->create();
$response = $this->post('/login', [
'username' => $user->username,
'password' => 'secret'
]);
$response->assertStatus(302);
}
If I add the line $this->assertAuthenticatedAs($user) at the end, I get the following error:
There was 1 failure:
1) Tests\Feature\Auth\LoginTest::test_login_valid_user
The current user is not authenticated.
Failed asserting that null is not null.
/home/vagrant/code/my_project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithAuthentication.php:89
/home/vagrant/code/my_project/tests/Feature/Auth/LoginTest.php:39
The same is happening on my register test, after the user is registered, when I try to check $this->assertAuthenticated() I get the same error.
So, I thought about session problems related to Vagrant/Homestead, but I just started to use them and couldn't find any hint about it. And I'm very new to PHPUnit and testing in general, I'm just starting to understand how it works.
The problem is connected with caches.
First of all file phpunit.xml must be read because you need: <server name="APP_ENV" value="testing"/>
Before your tests use command
php artisan config:clear
After that your dump(config('app.env')); will be testing (not local).
Then all works.
I'd been experiencing same problem. For unit tests CSRF token verification should be disabled, but only if you are running under APP_ENV=testing. I though phpunit.xml was overriding my "local" config so it was set to "testing". It was not, because PhpStorm was not reading this file.
If you are using PHPStorm don't forget to check path to default config file - phpunit.xml. (Settings -> Languages&Frameworks -> PHP -> Test frameworks)

TestCafe: Uncaught ReferenceError: pagespeed is not defined

New to TestCafe.
Expected
Given .js below, expected behavior when running testcafe chrome this.js is to click on the header logo.
Actual
Uncaught ReferenceError: pagespeed is not defined (at the click below).
On our prod site, this error doesn't happen so most likely some configuration (possibly my version of Apache?) but I wanted to make sure there weren't any TestCafe specific issues. Followed installation using the standard docs (npm)
Thanks in advance!
import { Selector } from 'testcafe';
fixture `A set of examples that illustrate how to use Little Passports`
.page `https://xxx.xxdev.us/`;
test('My Company', async t => {
await t.
click('.header-logo');
});
I think I'll currently get around this by adding -e, but I'll keep this open just in case there's something else to consider...
By default, a test fails when there is a JavaScript error on page. The "-e (--skip-js-errors)" parameter allows running tests by skipping this JS error.
To check if there are any errors on your page, open your browser console. If there are any, you can either fix the errors at the application level (a preferable approach) or skip them during test run using the "-e" parameter.

Can I run Durandal's Tests Framework outside of PhantomJS?

The Durandal Test Framework runs Jasmine tests within PhantomJS.
Where I'm implementing this for the first time I'm getting a lot of errors, and reading through these on the command prompt is proving to be very tedious.
If I load up the spec.html file in my web browser, it tells me that no specs were found:
Yet PhantomJS is able to find the specs with no problem:
Is there a way I can configure these Jasmine tests to run through my web browser and not through (or as well as) PhantomJS?
I've set up a new index.html file and have replaced the var runTests = ... section with a simple require() call:
require(['../test/specs/system.spec.js']);
Durandal's system.spec.js file is loaded in the browser, but Jasmine is still stating that no specs were found.
Jasmine's tests weren't being run because I wasn't telling it to re-execute. The solution to this was to simply re-execute by calling this within the require callback:
require(['../test/specs/system.spec.js'], function() {
jasmine.getEnv().execute();
});
Note: A drawback of this is that the 'no specs found' bar is still present and the 'raise exceptions' control on the re-executed specs doesn't appear to function:

RSpec and getting puts or logger.info to work

When I'm running my specs like "rspec ." from the command line, I can see puts or logger.info in the console, if i call that code in my spec. However, if the call to logger.info or puts is in my controller which I'm testing, it doesn't output to the test.log file or the console window.
I'm using RSpec 2 and Rails 3.0.4
Also, this is a refinerycms site, but we have a couple of controllers external to the Refinery CMS we are trying to test. When I do a puts or logger.info in a normal site, it seems to work fine, even running RSpec.
Thanks.
Okay so we finally figured this out.
The issue is that Refinery requires a default user to be created or it does not let you hit front end pages. When you first fire it up, it prompts the user to create a default admin login. So when we were running our tests, our code was never getting hit. Refinery was redirecting the "browser" during test time to the "create a first user" page.
We created a seed with a default user and then everything worked again. So the issue was never that doing a "puts" or "logger.info" didn't work in refinery or rspec. It was that during testing, we never were getting to our controller.