How to run execute shell command in jenkins in different terminals - jenkins

I am running my protractor test through jenkins and my package.json looks like this:
{"name": "ProtractorTest",
"version": "0.0.1",
"main": "conf.js",
"scripts": {
"setup": "npm install && node node_modules/protractor/bin/webdriver-manager update",
"e2e-start": "node node_modules/protractor/bin/webdriver-manager start",
"test": "protractor protractor.conf.js"
}
I am trying to run script using jenkins execute shell build step like below
Jenkins screenshot
but this tries to run setup,e2e-start,test one after other. Since "e2e-start" starts selenium server,so I see in console "INFO - Selenium Server is up and running...." and then npm run test is never run . I think it's because "npm run test" should be run in different terminal because when we run manually, we start server in one terminal and run test in different terminal. So, how can I achieve this using jenkins.

Try to use the bellow mentioned option in the config file then protractor will take care of starting and stopping of server itself, then you wont need to start and stop wendriver manager
directConnect: true
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
Also you can mention selenium server jar too.
seleniumServerJar: '../utils/selenium-server-standalone-2.53.1.jar',
seleniumPort: 4444,
Another approach would be to use jenkins selenium pluggin

For phantomjs its easy.
Download the selenium server jar and save it in a folder.
in protractor conf.js file comment out directConnect and seleniumAddress.
Include them in your config.
seleniumServerJar: 'location of the jar',
seleniumPort: 4444,
These setting will start the selenium server before tests starts and shut it down gracefully when test finishes. you wont need to bother about starting selenium server explicitly.
Note: use selenium-server-standalone-2.53.1.jar if you are using java 7

Related

Unable to run single PHP-test in PhpStorm (inside Docker-container). Error: Cannot open file "/path/to/my/project/tests/SomeTestClass.php"

Running all tests (works)
When I run all tests inside PhpStorm, then I go to "Run" >> "MyProject PhpUnit Test". This outputs and runs a command like this:
[docker-compose://[/path/to/my/project/docker-compose.yml]:php/]:/usr/local/bin/php /var/www/docroot/bin/phpunit --configuration /var/www/docroot/phpunit.xml.dist --teamcity
That runs all tests inside PhpStorm, so far so good!
Running single test (does not work)
If I go to a single test, right-click on the test-name and click:
"Run testAppendShortToAnswers..."
Shortcut: CTRLShiftR
then it outputs and runs a command like this:
[docker-compose://[/path/to/my/project/docker-compose.yml]:php/]:/usr/local/bin/php /var/www/docroot/bin/phpunit --configuration /var/www/docroot/phpunit.xml.dist --filter "/(App\\Tests\\Entity\\CardTest::testAppendShortToAnswers)( .*)?$/" --test-suffix CardTest.php /path/to/my/project/tests/Entity --teamcity
And throws an error immediately:
Cannot open file "/path/to/my/project/tests/Entity.php".
Process finished with exit code 1
I'm assuming that it's because it tries to access that file, not from inside my Docker-container, but rather from my host-machine.
How do I fix this, so I can run a single test in PhpStorm?
Info about the setup
I struggled a bit setting up PhpStorm to run the tests, but you can see the big problem I had (and the solution) alongside links and whatnot here.
I'm on a Mac. It's a Symfony-project, where PhpUnit is located in a folder in the project-root (/bin/phpunit). So it's not installed via Composer.
I'm not really sure why it's setup this way.
Solution attempt 1: Running single test from the terminal
If I go to the terminal and run this command:
docker-compose exec php /usr/local/bin/php /var/www/docroot/bin/phpunit --filter testAppendShortToAnswers
The it runs as it should. Hmm... But I ideally I would like to run it straight from PhpStorm, so I can utilize the CTRLShiftR-shortcut.
#LazyOne pointed me in the right direction.
It was because I had a path mapping setup incorrectly.
So by changing that, then it works now:
I had it like this:
/Users/MYUSERNAME/Code/MYPROJECTNAME/some-wrong-project -> /var/www/docroot
And it fixed it to change it to:
/Users/MYUSERNAME/Code/MYPROJECTNAME/the-project-I-am-working-on -> /var/www/docroot

How to run PHPUnit test inside a running container

I use PhpStorm in development. To run a test I do below 3 commands:
docker-compose exec app bash
cd app/
vendor/bin/phpunit unitTest/Sample.php
I want to be able to run the test just by clicking the "Run" button inside PhpStorm.
I tried to accomplish it using docs from IntelliJ but they overwhelmed me.
I thought I just need to change the interpreter path but couldn't understand how to attach to a running docker.
First you need to add your Docker-compose based interpreter. See this guide.
Second, add a PHPUnit configuration based on this interpreter, see "Integrate PHPUnit with a PhpStorm project".
After that you should be able to simply Run the tests using IDE UI.

Build executable for windows with Vue CLI Plugin Electron Builder in linux

I'm trying to build an executable file for windows from my linux but so far I have not been able to do it.
According to the documentation, it tells me that here I could configure, for example, the output folder.
pluginOptions: {
electronBuilder: {
outputDir: 'desktop-for-windows',
},
},
and if it works but does not say anything about how to change the platform (s.o) to build.
also try testing the following command:
npm run electron:build --win
but by default it builds for linux
Ran into same thing trying to move from an older boiler plate to using Vue-CLI 3 just now.
Run this from within the project directory and see if it works:
./node_modules/.bin/vue-cli-service electron:build --windows
I got the --windows from the ui.js file in the vue-cli-plugin-electron-builder directory under node_modules. Other options are --linux and --macos. I'm surprised I don't see a --all flag or that all isn't the default.
If you add "build:win": "vue-cli-service electron:build --windows" under scripts in your package.json then you can instead run npm run build:win from there on.
I just faced the same problem and found pretty easy answer.
You can just run npm run electron:build -- --linux deb --win nsis in the project directory.
There is more about it here: https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#multi-platform-build

Cant find Angular error when running headless Chrome Protractor tests on Linux CentOS trying with both xvfb and not

Bit of a long winded one....
I have a Jenkins instance running on a Linux CentOS box. I have a Jenkins job on there which should run Protractor tests using Chrome headless, I have tried a number of configurations including using Xvfb and not using Xvfb and I always get the same result where the tests start to run and do the first browser.get command but after a few seconds the tests error with:
E/protractor - Could not find Angular on page
After the tests run a HTML report is generated and all the screesnhots are blank.
Here's the relevant code and config I'm using...
my protractor conf.js
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
// IMPORTANT: needed due to issue with versions of selenium and chromedriver
"--headless",
"--no-sandbox",
"--window-size=1024x768"
]
}
},
My jenkins config I run shell command...
npm -g install protractor
webdriver-manager update
webdriver-manager start &
Then to run the tests I use...
xvfb-run protractor --baseUrl='https://myurl.com' conf.js
I have xvfb configured in Jenkins and installed on the CentOS box. I have tried without using xvfb as apparently later versions of Chrome don't need it.
The same tests are also running headless locally on OSX without any issue so the only difference is the operating system I think.
I'm struggling to work out what else it might be.

Signing Windows Electron App

I have an Electron app that compiles fine on Windows using npm run ewin:
"scripts": {
"start": "electron main.js",
"pack": "build",
"ewin": "build --win --ia32 --x64",
"ewinsign": "export CSC_LINK=file:///${HOME}/certificates/certificate.pfx; export CSC_KEY_PASSWORD=\"$( cat ${HOME}/certificates/certificates_pw.txt )\"; npm run clean:win && build --win --ia32 --x64",
},
So I added the ewinsign in an attempt to get it to sign the app.
I based ewinsign on this discussion:
https://discuss.atom.io/t/signing-windows-app-installer/32511
ewinsign fails with this error:
'export' is not recognized as an internal or external command,
operable program or batch file.
I did not really expect it to work because I am running my build on Windows, and bash commands are not typically available on Windows.
Signing Windows apps should be something with a well known solution so I am hesitant to start hacking together my own solution.
In summary:
I am building my app on Windows.
I have my certificate located here: ${HOME}/certificates/certificate.pfx
I have a file with the password located here: ${HOME}/certificates/certificate_pw.txt
I can successfully build unsigned with npm run ewin.
How can I add a ewinsign command that will build a signed Windows app?
I ended up writing a bat script wrapper that sets the environment variables. That was easier to debug because I could add env statement to see what the environment variables were set to.
Here is the script:
set CSC_LINK=file://%USERPROFILE%/certificates/certificate.pfx
set /p CSC_KEY_PASSWORD=<"%USERPROFILE%/certificates/certificates_pw.txt"
npm run ewin
Of particular note is the =< batch syntax to read a file into a variable. and the /p syntax to only read one line.
If you wanted to use that command and try with the windows replacements, you would be looking for the following:
set is the command that you would use to create a windows
environment variable (instead of export)
type is the equivalent of the bash 'cat' for
windows.
What is {HOME} for you? Is that in your "C:\Users\"Your
User Name" directory? If so, you could use
%USERPROFILE% to get that value.
The resulting code would look something like this:
"ewinsign": "set CSC_LINK=file:///%USERPROFILE%/certificates/certificate.pfx; set CSC_KEY_PASSWORD=\"$( type %USERPROFILE%/certificates/certificates_pw.txt )\"; npm run clean:win && build --win --ia32 --x64"
However, I haven't tested that code, so I am not sure if it will work or not.
Now, I haven't code signed with electron-builder, but I would assume that you would use the windows build options to enforce a certificate. This would be setup in the "build" section of your package.json file:
"build":{
"appid":"yourid",
"asar": true,
"forceCodeSigning": true,
"win":{
"target": "...",
"publisherName": "..."
"certificateFile": "...",
"certificatePassword":"...",
"certificateSubjectName":"...",
"certificateSha1":"...",
"signingHashAlgorithms":"..."
}
}
You might have to play around with those values to get something working, but based on the documentation, that is how I would do it. Reference the parent options here

Resources