I have Protractor tests, and I run tests with command tests with protractor protractor.conf.js --suite full in VS code on my local. VS code run chrome instance and executed tests well.
After that I setup Jenkins job for Protractor tests. My steps:
Pull code form BitBucket
Execute windows command npm install
Executed windows command node_modules\.bin\ng e2e --webdriver-update
Jenkins opened chrome browser on http://localhost:49156/ ** and start with Protractor tests.
On Chrome browser my tests could to find element by ID,HTML,text, but when needed to click on element I have this error [31m- [39m[31mFailed: element not interactable.
This is piece of console output:
[15:37:51] W/element - more than one element found for locator by.buttonText("Create") - the first result will be used
Creating configuration for
[31m× Creating default configuration [39m
[31m- [39m[31mFailed: element not interactable
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 6.2.9200 x86_64)[39m
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 6.2.9200 x86_64)
at Object.checkLegacyResponse (C:\Program Files (x86)\Jenkins\workspace\newGen_protractor\NewGenProject\ui\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\Program Files (x86)\Jenkins\workspace\newGen_protractor\NewGenProject\ui\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\Program Files (x86)\Jenkins\workspace\newGen_protractor\NewGenProject\ui\node_modules\selenium-webdriver\lib\http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
From: Task: WebElement.click()
This is the Protractor tests:
it('Creating default configuration 2000 ', () => {
_home.get2000Configuration().click();
_descriptionModal.buttonStartCreate().click();
for (let i = 0; i < 4; i++) {
_wizardModal.buttonNext().click();
}
_descriptionModal.buttonCreate().click();
expect(_configurationView.getBaImage().isDisplayed()).toBe(true).then(function (result) {
expect(_configurationView.getNeb().count()).toBe(2);
expect(_configurationView.getmage().count()).toBe(2);
expect(_configurationView.getEngineImage().isDisplayed()).toBe(true);
});
});
Checking the error stack that you posted I can see this:
[15:37:51] W/element - more than one element found for locator by.buttonText("Create") - the first result will be used
My guess is that has more than one button with this "Create" text and your code is getting lost. I would suggest check upon the button names and make sure that only one has this "Create" label, for example.
Related
I have integrated Tosca with jenkins to run in local .The test runs successfully on jenkins .However I see below error in result.xml file .The tests run fine in Tosca its only in Jenkins that I see this error .What do I do?
This is the result.xml output
<testcase name="Shipping Costs" time="12.7" timestamp="2022-10-07T16:04:47.1086587+05:30" log="- Failed Shipping Costs {LogInfo='Execution will be continued with the next TestCase, because there was an error in the current TestCase.'} + Passed Open Web Shop - Failed Navigate to Log In Page {LogInfo='No matching tab was found with the following properties: Title=Demo Web Shop*'} ">
- Failed Shipping Costs {LogInfo='Execution will be continued with the next TestCase, because there was an error in the current TestCase.'} + Passed Open Web Shop - Failed Navigate to Log In Page {LogInfo='No matching tab was found with the following properties: Title=Demo Web Shop*'}
I am able to run the protractor using command prompt.
However, when I try to run protractor using jenkins, it started the selenium server but does not execute the browser and will fail due to timeout.
Is there any configuration that I need to do at jenkins side aside from the project path?
I also have tried to install the package manually to makesure its updated.
Below is the error when I try to build/run protractor using jenkins:
> webhis_jasmine# protractor C:\Users\user1\.jenkins\HISWEBJASMINE
> protractor conf.js
[12:06:44] I/launcher - Running 1 instances of WebDriver
[12:06:44] I/local - Starting selenium standalone server...
[12:06:46] I/local - Selenium standalone server started at http://10.190.40.39:56419/wd/hub
Started
[31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow.
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
[31mF[0mA Jasmine spec timed out. Resetting the WebDriver Control Flow.
[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m[31mF[0m
i tried to run webdriver-manager update only using jenkins just to check and it is giving below error:
C:\Users\user1\.jenkins\HISWEBJASMINE>webdriver-manager update
'webdriver-manager' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\user1\.jenkins\HISWEBJASMINE>exit 9009
Here is config file:
// conf.js
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
capabilities: {
'browserName': 'chrome'
},
specs: ['Patient_positive.js','Visit_positive.js'],
suites:{
Smoke: ['ChainLocators.js', 'Dropdown.js'],
Regression: 'ElementBasics.js',
Testbed: 'testbed.js',
PatientPositive: 'Patient_positive.js',
PatientNegative: 'Patient_negative.js',
VisitPositive: 'Visit_positive.js',
VisitNegative: 'Visit_negative.js',
EpisodeCPOEPositive: 'EpisodeCPOE_positive.js'
},
onPrepare:function(){
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: './test/reports/',
screenshotsFolder: 'images',
takeScreenshots: true,
fixedScreenshotName: true,
takeScreenshotsOnlyOnFailures: false,
cleanDestination: false,
showPassed: true,
fileName: 'Test_Report',
fileNameSuffix: '',
fileNameDateSuffix: true
})
);
},
jasmineNodeOpts:{
showColors: true
}
};
Is it related?
Update: I strip the spec to have to only 1 'it' and run. Manage to get a success result and report is generated, but i see the browser not launched as when running using cmd prompt.
C:\Users\hafizan.abdmulok\.jenkins\HISWEBJASMINE>npm run protractor
> webhis_jasmine# protractor C:\Users\hafizan.abdmulok\.jenkins\HISWEBJASMINE
> protractor conf.js
[15:14:40] I/launcher - Running 1 instances of WebDriver
[15:14:40] I/local - Starting selenium standalone server...
[15:14:43] I/local - Selenium standalone server started at http://10.190.40.39:52793/wd/hub
Started
Successfully open patient page
Successfully enter name
Successfully select title
Successfully select gender
Successfully enter date of birth
Successfully select ID type
Successfully enter idno= 850921141112
Successfully select Nationality= Malaysia
Successfully enter mobile no
Successfully enter patient address line 1
Successfully enter patient address line 2
Successfully enter patient address line 3
Successfully enter patient postcode= 57000
Successfully enter patient city= Bukit Jalil
Successfully select patient State= Kuala Lumpur
Successfully select patient State= Malaysia
[32m.[0m
1 spec, 0 failures
Finished in 63.169 seconds
CGM
[15:15:52] I/local - Shutting down selenium standalone server.
[15:15:52] I/launcher - 0 instance(s) of WebDriver still running
[15:15:52] I/launcher - chrome #01 passed
Finished: SUCCESS
Try using directConnect:true in your config file instead of seleniumAddress: 'http://localhost:4444/wd/hub',
before runing the test do the below activities
webdriver-manager clean
node node_modules/protractor/bin/webdriver-manager update --standalone --versions.standalone=3.8.0
Hope it helps you
One of my Jenkins job is executing MSTest. I am passing the following command to
Execute Windows batch command:
del TestResults.trx
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\MSTest.exe" /testcontainer:D:\Projects\Jenkins\TestResultVerificationFromJenkins\TestResultVerificationFromJenkins\bin\Debug\TestResultVerificationFromJenkins.dll /resultsfile:TestResults.trx /nologo /detail:stdout
At the time of execution, Console Output is displaying the following values:
Starting execution...
Results Top Level Tests
------- ---------------
Passed TestResultVerificationFromJenkins.UnitTest1.PassTest
[stdout] = Test is passed*
1/1 test(s) Passed
Summary
Test Run Completed.
Passed 1
Total 1
Results file: C:\Program Files (x86)\Jenkins\jobs\JenkinsTestResultReader\workspace\TestResults.trx
Test Settings: Default Test Settings
In the post build step, I have to pass the MS test result "Test is passed" to a HTTP Request.
Is there any way to save this result in a Jenkins variable so that I can pass that to HTTP Request?
Regards,
Umesh
Since you are in the postbuild step, would parsing the console output for the test result and sending it off to the HTTP Request be an option for you?
For example, using Groovy Postbuild plugin, you could write a small script that could do this.
Perhaps something like:
if(manager.build.logFile.text.indexOf("Test Run Completed. Passed") >= 0)
manager.listener.logger.println (new URL("http://localhost?parameter=Test+is+passed")).getText()
Is there a way to use node-inspector to debug unit tests with Jest? It would be nice to step through sometimes to see why tests are failing
I have tried a few ways
node-debug jest --runInBand
from the as well as starting up the inspector first eg
$ node-inspector
$ node --debug-brk .\node_modules\jest-cli --runInBand
and then navigate to http://127.0.0.1:8080/debug?port=5858
I have found that occasionally (1 in 10 or so times), the debugger opens the jest src files and its possible to debug them. Generally though, the scripts in the debugger only contain a 'no domain' folder and another irrelevant folder.
Also the test scripts themselves are never loaded in the debugger.
Has anyone tried this before?
Looks like the issue is that jest is using harmonize, which spawns a child process to ensure that the --harmony option is used.
harmonize/harmonize.js, lines 30-35
var node = child_process.spawn(process.argv[0], ['--harmony'].concat(process.argv.slice(1)), {});
node.stdout.pipe(process.stdout);
node.stderr.pipe(process.stderr);
node.on("close", function(code) {
process.exit(code);
});
I was able to successfully debug jest tests (although tests that use JSX transforms are incredibly slow) by commenting out the code that jest is using to spawn the harmonized process.
node_modules/jest-cli/bin/jest.js, last lines of the file:
if (require.main === module) {
//harmonize(); <--- comment out
_main(function (success) {
process.exit(success ? 0 : 1);
});
}
Then you can run:
$ node-debug --nodejs --harmony ./node_modules/jest-cli/bin/jest.js --runInBand
Jest relies on the --harmony flag being there, so that's why we need to add it back with --nodejs --harmony. We also add --runInBand so that the tests run in sequence, not in parallel.
This opens up the web debugger, and you can debug the tests, although it can be pretty slow to get to the test you want. Please comment if anyone knows a way to make this faster, and I'll update my answer.
You can add this to your package.json to make it easier to kick off:
...
scripts: {
"test": "jest",
"test-debug": "node-debug --nodejs --harmony ./node_modules/jest-cli/bin/jest.js --runInBand"
}
...
Of course, main concern with this solution is the editing of the jest source code. Will think about how to make a pull request to make this stick.
Created Github Issue Here: https://github.com/facebook/jest/issues/152
This is now officially supported with Node >= 6.3.
Quoting Jest documentation:
Place a debugger; statement in any of your tests, and then, in your project's directory, run:
node --debug-brk --inspect ./node_modules/.bin/jest -i [any other arguments here]
This will output a link that you can open in Chrome. After opening that link, the Chrome Developer Tools will be displayed, and a breakpoint will be set at the first line of the Jest CLI script (this is done simply to give you time to open the developer tools and to prevent Jest from executing before you have time to do so). Click the button that looks like a "play" button in the upper right hand side of the screen to continue execution. When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack.
Note: the -i cli option makes sure Jest runs test in the same process rather than spawning processes for individual tests. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time.
More information on the V8 inspector can be found here: https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js
Using Node 7.4.0, Jest 18.x, and the jest-environment-node-debug package (from this comment), it's now possible to use the chrome devtools to debug Jest tests:
$ npm install -D jest-environment-node-debug
$ node --inspect-brk ./node_modules/.bin/jest -i --env jest-environment-node-debug
Here's a Gruntfile.js config to automate #Sean's answer with Grunt.
grunt testd
OR
grunt testd --tests=MyTestName
OR
grunt testd --tests=MyTestName,AnotherTestName
Requires "node-inspector" (must be installed globally to get the node-debug bin in your path), "lodash", "jest-cli" and "grunt-shell" node modules.
var _ = require('lodash');
var commaSplitToRegex = function(input) {
return _.map(input.split(','), function(part) {
return '(' + part + ')';
}).join('|');
};
var getTestRegex = function(tests) {
if (tests) {
return '.*' + commaSplitToRegex(tests) + '.*';
}
return '.*';
}
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
shell: {
jestd: {
command: function() {
var testsRegex = getTestRegex(grunt.option('tests'));
var cmd = 'node-debug --nodejs --harmony ./node_modules/jest-cli/bin/jest.js --runInBand --config="test_utils/jest.json"';
if (testsRegex) {
cmd += ' "' + testsRegex + '"';
}
return cmd;
}
},
monkeypatchjest: {
command: 'sed -i.bak s\\/harmonize\\(\\)\\;\\/\\\\/\\\\/wtf\\/g ./node_modules/jest-cli/bin/jest.js'
},
unmonkeypatchjest: {
command: 'sed -i.bak s\\/\\\\/\\\\/wtf\\/harmonize\\(\\)\\;\\/g ./node_modules/jest-cli/bin/jest.js'
}
}
});
grunt.registerTask('testd', 'Run tests with debugger.', ['shell:monkeypatchjest', 'shell:jestd']);
};
I want to integrate the Specs2 test results with Jenkins.
I was added the below properties in sbt:
resolver:
"maven specs2" at "http://mvnrepository.com/artifact"
libraryDependencies:
"org.specs2" %% "specs2" % "2.0-RC1" % "test",
System Property:
testOptions in Test += Tests.Setup(() => System.setProperty("specs2.outDir", "/target/specs2-reports")) //Option1
//testOptions in Test += Tests.Setup(() => System.setProperty("specs2.junit.outDir", "/target/specs2-reports")) //Option2
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "console", "junitxml")
If I run the below command, it is not generating any specs reports in the above mentioned directory("/target/specs2-reports").
sbt> test
If I run the below command, it is asking for the directory as shown in the below error message:
sbt> test-only -- junitxml
[error] Could not run test code.model.UserSpec: java.lang.IllegalArgumentException: junitxml requires directory to be specified, example: junitxml(directory="xxx")
And it is working only if I give the directory as shown below:
sbt> test-only -- junitxml(directory="\target\specs-reports")
But sometimes its not generating all the specs report xmls (some times generating only one report, sometimes only two reports etc.).
If I give test-only -- junitxml(directory="\target\specs-reports") in the jenkins it is giving the below error.
[error] Not a valid key: junitxml (similar: ivy-xml)
[error] junitxml(
[error] ^
My main goal is, I want to generate the consolidated test reports in junit xml format and integrate with Jenkins. Kindly help me to solve my problem.
Best Regards,
Hari
The option for the junitxml output directory is: "specs2.junit.outDir" and the default value is "target/test-reports".
So if you don't change anything you could just instruct Jenkins to grab the xml files from "target/test-reports" which is what I usually do.
Also you might have to enclose your sbt commands in Jenkins with quotes. This is what I typically do:
"test-only -- html junitxml console"