I am new to E2E testing with Protractor. I have created 3 test specs. Each test spec has one describe and several it in it. I want to run all specs sequentially.
My protractor config file with specs listed like this
specs: [
'tests/../test1_spec.js',
'tests/../test2_spec.js',
'tests/../test3_spec.js'
]
When I run my protractor config file all the tests start running simultaneously.
I am not sure if my config file is wrong or something else which is triggering the simultaneous tests runs.
This should not happen - what do you mean all the tests start running simultaneously? How many browser winwos do you have, and what's the output?
I have only one Browser window. When the first test spec runs, login is successful and while its trying to navigate then second test kicks in and fails as it cannot find the login page. The browser results in 404 error (page not found) and the protractor has the following error
Starting selenium standalone server...
Selenium standalone server started at http://../wd/hub
..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1702
throw error;
^
NoSuchElementError: no such element
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 11 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=WIN8, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=..\AppData\Local\Temp\scoped_dir12100_16493}, rotatable=false, locationContextEnabled=true, version=34.0.1847.116, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
at new bot.Error (..\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:109:18)
at Object.bot.response.checkResponse (..\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:106:9)
at ..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:276:20
at ..\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:1178:15
at webdriver.promise.ControlFlow.runInNewFrame_ (..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1598:20)
at notify (..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:428:12)
at notifyAll (..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:397:7)
at resolve (..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:375:7)
at fulfill (..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:493:5)
at ..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1465:10
==== async task ====
WebDriver.findElement(By.id("UserName"))
at webdriver.WebDriver.schedule (..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:267:15)
at webdriver.WebDriver.findElement (..\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:700:17)
at Protractor.findElement (..\node_modules\protractor\lib\protractor.js:748:25)
at Fn.Object.create.findElement.value (..\node_modules\astrolabe\lib\astrolabe\base.js:46:63)
at Fn.module.exports.Page.create.username.get (..Pages\Base\LoginPage.js:7:47)
at Fn.module.exports.Page.create.login.value (..Pages\Base\LoginPage.js:14:13)
at null.
at jasmine.Env.describe_ (..\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:907:21)
at jasmine.Env.describe (..\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:892:15)
[launcher] Runner Process Exited With Error Code: 8
Process finished with exit code 1
It sounds like the tests are running sequentially but you have a synchronization problem where your spec is not waiting until login is done before it moves on. How are you doing your login? Here's a working example from Protractor's own test suite: https://github.com/angular/protractor/blob/master/spec/withLoginConf.js
Note how it uses browser.driver.wait to make sure login is done before moving on.
I tried running the protractor config using the above example but still it doesn't seem like its running sequentially.
The above example will only wait until the login is successful and it triggers the second test without waiting for the first test to finish. I need the first test to run completely and finish and then the second test should start to run.
I have a similar issue in my tests. It seems like it depends on where I put my navigation logic and when it gets executed. E.g. if I have a describe suite that doesn't need a page reload or to navigate somewhere (if I just want to verify that a bunch of things are present for example), then I'd put the browser.get() inside the describe, but not inside a method (beforeEach or it), so it only gets called once and speeds up the testing.
But it seems like all the describes are called before their internal tests are called, messing up the navigation.
@KasMA1990 that's how Jasmine works - anything inside a describe but not inside an it will get called before any tests run.
Oh damn, sorry! I'm still new to this d:
@nethulap what test framework (jasmine/mocha) are you using? Could you share your tests?
The problem is fixed now. I have changed the way every test navigates. The following is the solution for the above problem.
For every test spec inside the describe in the beforeEach I am calling the Login function and in the afterEach the logoff function.
This ensures the second test never interferes with the first one until the first test finishes its execution completely.
My code looks like this
describe('Test1', function() {
beforeEach (function(){
loginPage.login();
});
afterEach (function(){
loginPage.logoff();
});
it('should create...', function() {
});
});
Thank you for the help.
I tried running the protractor config using the above example but still it doesn't seem like its running sequentially.
The above example will only wait until the login is successful and it triggers the second test without waiting for the first test to finish. I need the first test to run completely and finish and then the second test should start to run.but the first and second files are in different folders.
i am also getting same issue, i have one describe associated with one "it"
and similarly, 10 different suites with each spec, when i am executing with Jenkins, it is not executng sequencially, any suite is getting triggered,
I wan to know is there any annotation or keyword in Jenkin or Jasmine, to make suite run sequentially ione after the other like we used to work in TestNG using @priority annotation
For the above mentioned problem, the alternative way, i think so is, to place all these files names in a sequential order as a suite in one file and make the trigger to collect the testcase from that file which contains the all the testcase names.
+1
Most helpful comment
It sounds like the tests are running sequentially but you have a synchronization problem where your spec is not waiting until login is done before it moves on. How are you doing your login? Here's a working example from Protractor's own test suite: https://github.com/angular/protractor/blob/master/spec/withLoginConf.js
Note how it uses
browser.driver.waitto make sure login is done before moving on.