We are using Jasmine 2 with WebDriverIO to do some web based testing and we want to share the suites between devices / browsers.
This gives us some issues in that some features are disabled on devices so can't be tested and should be skipped. They shouldn't be failed as the feature is not designed to display on that device.
Jasmine has the ability to mark as pending pending() however I can't seem to find a way to do this without wrapping spec's in if statements or manually calling it inside each it.
I need to do this automatically so manually marking the specs or suites is not a good option.
Example the below would only want to run on a desktop not a mobile device
it('shows the product on the checkout', () => {
expect(map.items.getText()).toEqual('1 Item);
});
Related
In an AngularJS application is it possible to detect if the environment is Protractor?
I would like to disable certain functionality such as Geolocation when running my tests. It's not something I want to test at the moment and I am pretty sure it is what is causing my tests to fail to run.
In my App I use window.jasmine to disable certain polling actions when running Jasmine tests so something similar would be good.
i.e.
if(!window.protractor) {
geoLocationRun()
}
This doesn't work and there doesn't appear to be anything I can use on Window.
Note: I know I can mock out the geolocation which I can do if this isn't possible. Perhaps this is the best approach in any case however it would be good to know if there is a suitable solution. How do I enable geolocation support in chromedriver for Selenium?
I would recommend you to move your geo location code into an angular module. Then you can mock the module in your protractor tests using browser.addMockModule
http://angular.github.io/protractor/#/api?view=Protractor.prototype.addMockModule
I am using protractor to test my angular app, where most of the views are accessible for authenticated users only.
Currently, I placed the login action in beforeEach:
beforeEach(function() {
browser.get(site + '/account/login');
element(by.id('Username')).sendKeys('testuser');
element(by.id('Password')).sendKeys('letmein');
element(by.css('[value="Log In"]')).click();
});
The problem is for every it('should....') test, the webdriver visits the login page and perform the same log in ritual over and over again.
I guess there must be a better way to do it. How can we set up correctly so that the webdriver login only once and then perform all the it('should....') tests?
This can be done via the onPrepare field of the protractor configuration file.
An example configuration file with login is provided in Protractor itself.
onPrepare: function() {
browser.driver.get(env.baseUrl + '/login.html');
browser.driver.findElement(by.id('username')).sendKeys('Jane');
browser.driver.findElement(by.id('password')).sendKeys('1234');
...
}
Alternatively, you can make use of the fact that Jasmine tests are ordered. Thus, instead of logging in before every test, you can have your first it login.
I typically organize my Jasmine tests into larger suites, with the first it signing in, and the last it signing off.
The obvious disadvantage is that your tests are not entirely independent, but in return test execution is substantially faster. You can even argue that doing multiple things after logging in is more realistic than logging on and off for every action.
Yet another solution is to use the Jasmine 2.x beforeAll and afterAll notations of (see this answer). This does require that you use the newest version of Protractor, as pre 1.5 versions of Protractor only worked with Jasmine 1.x.
I used to do performance testing on websites mostly with JMeter scripts.
However, more and more projects are build with frontend MVC's, such as AngularJS and a current project is loading all of it's content via angular view files, REST calls etc.
Unfortunately, JMeter doesn't execute any javascript thus my load test return me the homepage in just (400ms).
In real, it actually takes several seconds to load in a browser. When I check the response data, it does not contain any data yet due to Angular.
Instead of investigating the network traffic and individually loading each component (e.g. profile.html, notification.html, REST calls etc. ). Is there a product on the market or some best case I could follow that is similar to executing JMeter scripts, but considering javascript execution and loading of external resources due to javascript?
(I am not planning to profile javascript execution times. This is still to test if the infrastructure behind is capable serving xyz simultaneous users)
Although JMeter isn't capable of executing client-side JavaScript it can record relevant requests via HTTP(S) Test Script Recorder. Once recorded you should be able to combine all the standalone requests into one "aggregate" using JMeter's Transaction Controller
If this easy approach for some reasons doesn't play for you check out How to Load Test AJAX/XHR Enabled Sites With JMeter for more options and clues.
I use Chrome dev tools to do this kind of performance tests in web apps.
I suggest you to read the Chrome Profiling docs (https://developer.chrome.com/devtools/docs/javascript-memory-profiling). All the section of Performance and Profiling in goolge documentation is really good!
You can try to use the option 'Use as Monitor' for the requests you fire up from your test.
http://jmeter.apache.org/usermanual/build-monitor-test-plan.html
They are performance killers, though. Another option is to use the listener 'Save Responses to a File' to see if the end HTML is delivered. It should not give you the ideal result but it might help.
If you want to track down performance of XHRs for a single user, you can try to play with Selenium and BrowserMob Proxy, but it is not under the stress testing, but functional testing.
You can try https://github.com/kidk/felt it is build for this specific purpose.
It uses PhantomJS/SlimerJS to generate load to a website, so you get all the API/JS/CSS and image calls you would get like in a normal browser. It is still a young project, but it might be the solution you are looking for.
(This is my personal project)
Is there any way to trigger my javascript modules in jmeter to check whether they are working properly during load/performance tests
JMeter is not a browser so it isn't able to execute client-side JavaScript. All that JMeter is able to do in this regards is:
Download scripts along with other embedded resources like images and styles (but do it only once per virtual user) to simulate real browsers behavior more or less closely.
Simulate JavaScript-driven calls like AJAX/XHR via separate HTTP Requests
The most common practice of web application monitoring during performance session is manually accessing the application under test and assessing it's responsiveness and behavior.
This process can also be automated using JMeter's WebDriver Sampler Plugin which allows to invoke arbitrary Selenium code to orchestrate one or several real browsers to check i.e. actual page load speed during performance test session.
I am writing a chrome packaged app, using angular JS.
My setup uses grunt/karma/jasmine for building/unit testing, and everything was fine until I started using the chrome.* API. This of course was an issue as I had Travis-CI set up to use PhantomJS, but Phantom doesn't know about the chrome global var.
Is there a way to run unit tests with karma that will not throw ReferenceError: Can't find variable: chrome for testing packaged apps, and so pass Travis-CI testing
Is there a way to suppress the errors that PhantomJS is throwing (this sounds bad already)
Few thoughts:
You could polyfill/stub the chrome.* apis before running your tests, to simulate the chrome app environment. Not sure if anyone has already done this already (i.e. here is one quick example for node-webkit I found). It sounds like a useful library someone should write ;)
Just skip those tests that you know will always fail on PhantomJS, by wrapping jasmine test definitions with a guard like if (!is_chrome_app) return;. One clean way to do this in jasmine is to create a defineChromeAppOnly helper that skips the define call if its not a chome app.
You probably want an alternative system for actually running tests inside a real chrome app. I've always just built my own crude CI for this (or done it manually), but since this would be cool to make easier for CI, I've filed a request with Travis CI Team to support Chrome Packaged Apps. Star that issue if you are interested in what they reply.