Basic Authentication and Certificates handling with Protractor - angularjs

I need to write some automated tests for our AngularJS apps with Protractor. Currently I am facing two problems:
before the page is fully rendered some calls to services are made that require user name and password. These are prompted with a basic auth popup. I am not able to get my hands on this popup as all attempts to get the window handles fail. (or more explicit: the callback for the promise is never executed)
for a different case I am getting the "select certificate" popup which I am also unable to get my hands on.
For both cases I have now the question if I am even able to ever capture them somehow or is it just that these are not accessible via automated tests via WebDriver? Currently I am trying to test the app with Chrome and PhantomJS but I would prefer to have them running with PhantomJS for an easier integration to our build environment.

There is a possibility to automatically select the certificate with Chrome. Just have a look at the documentation:
http://www.chromium.org/administrators/policy-list-3#AutoSelectCertificateForUrls

I had the problem and when such security pop-up occurs I couldn't handle them with WebDriver. PhantomJS of course is even worse in such case.
You have 2 or 3 options here :
deploy in a environment where security is not a concern, test with WebDriver the app, and test security manually in a prod-like env.
test with sikuli, there is zero adherence with the app under test, I did test this way, combined with Jenkins Jacoco etc it was very powerful once you build a DSL on top of the jar (don't use the GUI tool)
a third way is to combine sikuli and WebDriver, letting sikuli do the job only when required, but I didn't follow that way since mixing up approaches is somehow ugly.

Related

Playwright e2e testing. What to do with oauth2 or email-passwordless authentication

I am starting to do e2e tests with playwright.
Most of the application requires to be authenticated. Automating this with a username/password mechanism is quite easy. The problem is that the app I want to test has only two authentication mechanisms: Github OAuth and email authentication links. Specifically I am using next-auth in a NextJS project.
I don't know how should I e2e test this with Playwright, the options I have considered are:
Completly mocking the authentication using a mock user and a mock session and then append the session token in the test context (as it is described here in the official docs).
Creating a Github user and/or an email account for the tests and somehow truly use them in playwrigth.
The first option is much easier to implement but then it's not e2e testing anymore. The second option looks difficult to implement and I don't know if it is recommended. I don't know if there are smarter or more standarized ways to proceed with this.
I disagree with #mostafa as an e2e test should be as closely to production as possible. Even if you're using a well tested library, you could still use it wrongly. Cypress has the mentioned issue recognized and developed a solution with a new feature: https://cypress.io/blog/2022/04/25/cypress-9-6-0-easily-test-multi-domain-workflows-with-cy-origin/
It's especially useful for login workflows provided by external services.
The keynote here is that you don't need to write e2e test to test the authentication flow because you're using next-auth ( which I think is a well-tested library).
So I think you should go for the first option .

Can we automate an application which runs on mobile browser(Not mobile app) using Selenium Webdriver

There is an application which users access on Samsung NOTE devices. Requirement is to automate the regression suite on mobile(Samsung NOTE). This application works on PC also, and I have managed to automate using selenium on PC successfully.
Could anyone help me know, if we can use selenium to automate the mobile version of it? I mean can my selenium script automate the mobile browser.
If we can't achieve, what automation tool can I use to automate the same?
Based on the provided comment you have 2 approaches you may take at this point:
Using Chrome options and mobile emulation params in WebDriver as DesiredCapabilities refer to this page for more details:
https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation - you can do the same from your own browser in dev tools. This should be enough for 90% of cases, however if you want to make sure that env you're running your tests is as close to real users as possible see 2.
Using special tools that create specific instances of WebDriver, like Selendroid or Appium - in this case you may either run your tests on emulated device(by creating instances from Android SDK or from Xcode) or you even have ability to connect real devices and execute your tests on them

How to do performance testing for multiple user using Chrome Dev Tool for angular JS Web Site

I have developed an Angular JS Web Console. Web Console is basically creating, deleting, retrieving and deleting Users.
I want to do its performance testing using Chrome Dev Tool or Jmeter
If I use Jmeter how can I actually monitor the behavior of web console itself because from Jmeter I can only check the response time of API.
If I use chrome dev tool then how can I test it for multiple users against post and get operations.
For Example I have a Scenario that 10 Users are registering or signing in at a time. How can I test this behaviour.
OR
50 Persons are creating or deleting or retrieving a user using a form at a time.
OR
What will be the behavior of web console if 50 users are using web console at a time.
NOTE: Web Console is deployed on server. I want to test it locally and on server as well.
Need help. Thanks in advance!
Server side performance and client-side performance are different beasts so you can break down your performance testing requirements into 2 major parts:
Conduct the required load onto your web console using JMeter HTTP Request samplers. Make sure you configure JMeter properly to handle cookies, cache, headers, embedded resources (scripts, styles, images). See How To Make JMeter Behave More Like A Real Browser article for comprehensive explanation with regards to how to configure JMeter properly. If you need the requests to be fired in exactly the same moment of time also consider Synchronizing Timer
As JMeter neither actually render pages nor executes client-side JavaScript you can check client-side performance using one of below approaches (or any combination)
Using YSlow software
Using aforementioned Chrome Dev Tools
Using WebDriver Sampler (which provides Selenium and JMeter integration) so you will be able to measure page rendering time. If necessary you can add custom scripting logic using Navigation Timing API to get some extended information on page loading events in automated manner

Selenium parallel test running conflict between multiple browser instances b/c share local storage?

I started setting up protractor tests for an angular SPA. To speed up test running, I've setup Selenium to run tests in Firefox and Chrome using multiple instances for each browser.
Before each test case we clear localStorage so we are certain of our starting position.
However, today I uncovered a conflict. Since a browser with two instances, if pointing at the same domain, it will share localStorage between the two. So if I have two tests running in parallel, and one requires a user to be logged in, while the other requires user to be logged out -- well, the first test will log user in, and now the user in the second browser instance will also be logged in (because localStorage got set/updated in both).
So now, one of my tests just failed because it found itself on the wrong page.
Is there any simple way to overcome this problem? (That does not involve setting up a server and multiple instances, or spending $2,000/mo on Saucelabs/Browserstack...)
Alright, i was facing the same problem and here is the solution i got:
You will have to make a copy of the framework and store it in two different places in your local machine.
You will have to create different listening ports for each instance launch in selenium, you can do the same by configuring the testng.xml that is being used for launching the automation tests.

Google App Engine, Load Testing on the Appspot server

I am a beginner in GAE and still evaluating if I should use this for my school project. I need to show that how an application can be scalable, the definition I wanna use here is whether it can serve 1000s of users concurrently.
Now load testing is one way of doing it. But load is futile when Google will scale out the application to a number of different instances depending on the load.
So hence, I am thinking of simulating data store read/writes access memcache etc to show the scalability prospects of the application.
Now, using JUnit Test is a good way to do this. But they can only be run locally. Is there a way to run them on the server, the actual production environment? If that can be done, then I can just write these tests and execute them via eclipse and I should be done!
The other way is to use functional testing with selenium to simulate the load and actual user conditions but this would most probably crash my computer and also not be concurrent.
The other option is to use a python load testing script and use sample json data to throw requests at the server urls. This however I tried but I cant test the options where genuine user interaction is needed since the live site requires a google sign in.
Any ideas where do I proceed to?
Look at either Siege (http://www.joedog.org/siege-home/) or JMeter (http://jmeter.apache.org/) for doing remote testing of your apps. The problem is though that you will hit the limit of your actual testing machine before you hit the limit of what you're trying to test so a lot of people spin up a few EC2 instances and run the load tests from there. Seige is very simple, it just reads a list of urls from a text file and clobbers the server as hard as you tell it to. JMeter lets you create more robust tests that can do things like log into a server and log more fine grained details about how your app behaves.
Those are the two best free and easy to use tools out there (IMHO).
It sounds like you really want to simulate datastore operations.
You can write a HTTP request handler that loads your junit tests and calls them, then either dump the results to log or as the HTTP result.
If they take a long time to run, you can run them on a backend instance.
Along the lines of Rick's suggestion, you can also probably run a test on a backend instance that makes HTTP requests to your frontend instances using the async HTTP API, and cause your front end instances to do a lot of work, if that's what you need to simulate.

Resources