How to Reuse Jasmine Tests

I have the following test in Jasmine that I need to run for two different URLs, these 2 urls are different versions of the same product:

describe('TEST ',function(){
    var basePage = new BasePage();
    var page1 = new Page1();

    describe('TEST',function(){

        beforeEach(function(){
            browser.get('URL-1.html');
        });

        it('REUSE THIS TEST' , function (){
            browser.wait(EC.visibilityOf(viewerWidgetPage.videoPlayer));
            page1.videoControls.click();
            expect(basePage.hasClass(page1.videoPlayer, 'vjs-playing')).toBeTruthy();
            page1.audioControl.click();

            //Verify that the video property is muted.
            browser.executeAsyncScript_(function(callback){
                callback(window.player.muted());
            }).then(function(isMuted){
                expect(isMuted).toBeFalsy();
            });

            page1.audioControl.click();

            //Verify that the video property is muted.
            browser.executeAsyncScript_(function(callback){
                callback(window.player.muted());
            }).then(function(isMuted){
                expect(isMuted).toBeTruthy();
            });


        });

    });

Is there any way to use “this” “IMPLEMENT THIS TEST” in another test?

+4
source share
1 answer

One option would be to iterate over the test URLs:

describe('TEST ',function(){
    var basePage = new BasePage();
    var page1 = new Page1();
    var urls = ['URL-1.html', 'URL-2.html'];

    urls.map(function (url) {
        describe('TEST ' + url,function(){

            beforeEach(function(){
                browser.get(url);
            });

            it('REUSE THIS TEST' , function (){
                browser.wait(EC.visibilityOf(viewerWidgetPage.videoPlayer));
                page1.videoControls.click();
                expect(basePage.hasClass(page1.videoPlayer, 'vjs-playing')).toBeTruthy();
                page1.audioControl.click();

                //Verify that the video property is muted.
                browser.executeAsyncScript_(function(callback){
                    callback(window.player.muted());
                }).then(function(isMuted){
                    expect(isMuted).toBeFalsy();
                });

                page1.audioControl.click();

                //Verify that the video property is muted.
                browser.executeAsyncScript_(function(callback){
                    callback(window.player.muted());
                }).then(function(isMuted){
                    expect(isMuted).toBeTruthy();
                });


            });
        });
    });
});

Another approach that is likely to scale better is to use multiCapabilitiesand add the desired specifications to each of the features that parameterize the url under test.

, :

multiCapabilities: [
    {
        browserName: "chrome",
        url: "URL-1.html"
    },
    {
        browserName: "chrome",
        url: "URL-2.html"
    }
],

getProcessedConfig() url:

beforeEach(function () {
    browser.getProcessedConfig().then(function (config) {
        var url = config.capabilities.url;
        browser.get(url);
    });
});

- .

+4

Source: https://habr.com/ru/post/1619545/


All Articles