Sameera De Silva
2 min readDec 31, 2019

How to run spec.js files in Firefox and Chrome conditionally and in none parallel mode in Protractor with Jasmine .

Test scenario- I want to run some of spec.js files in firefox and some of spec.js files in Chrome The tests must be run in none parallel mode and first run in a one browser type and then in the other browser type . How do I achieve that ?

Steps-

In cmd type webdriver-manager start

After that open a cmd line as Admin and go to config.js file location and enter the below command (twobrowsersfortwospecsconfig.js is my file name )

protractor twobrowsersfortwospecsconfig.js

In the config.js , I have mentioned draganddrop.spec.js to run in Firefox while iframes.spec.js to be run in Chrome .

So the spec.js will be executed as per the requirement .

//protractor twobrowsersfortwospecsconfig.jsexports.config = {framework: 'jasmine',directConnect: false,multiCapabilities: [{browserName: 'firefox','moz:firefoxOptions': {args: ['--verbose'],binary: 'C:/Program Files/Mozilla Firefox/firefox.exe'//Need to start cmd via admin mode to avoid permission error},specs: ['src/com/sam/scriptjs/draganddrop.spec.js']},{browserName : 'chrome',chromeOptions: {args: [ "--start-maximized" ]},specs: ['src/com/sam/scriptjs/iframes.spec.js']}],maxSessions: 1,//To run in sequential mode so first Firefox then chrome//without max session it will open two windows at the same time for both browsersseleniumAddress: 'http://localhost:4444/wd/hub'}

My spec.js files are in src/com/sam/scriptjs folder.

draganddrop.spec.js

//draganddrop.spec.jsdescribe('drag and drop trial', function() {//Each single it function is a test scriptit('first spec', function() {browser.driver.get('https://codef0rmer.github.io/angular-dragdrop/#!/');expect(browser.getTitle()).toEqual('Drag and Drop for AngularJS');});it('Drag and drop', function() {var from=element(by.model('list1'));var to=element(by.model('list2'));//drag and drop source  to Destination// browser.actions().dragAndDrop(from,to).perfrom();browser.actions().mouseDown(from).mouseMove(to).mouseUp().perform();browser.sleep(7500);});})

iframes.spec.js which is the other spec.js

//iframes.spec.jsdescribe('Iframe example', function() {//Each single it function is a test scriptit('Iframe handling', function() {browser.driver.ignoreSynchronization = true;browser.waitForAngularEnabled(false);browser.driver.manage().window().maximize();browser.driver.get('http://demo.automationtesting.in/Frames.html');expect(browser.getTitle()).toEqual('Frames');});it('Iframe handling', function() {//right click near the element if it show view frame source it means it'sinside of an iframebrowser.switchTo().frame(0);//we can give name or index//sendkeys inside of an element in an iframeelement(by.xpath('//input[@type="text"]')).sendKeys('Hi element inside of a one iframe');// switch back to main containbrowser.switchTo().defaultContent();//click element that not in any iframeelement(by.linkText('Home')).click();});})

No responses yet