How do i inject node ENV values into Testcafe Studio test - testing

We are using TestCafe Studio to generate tests from the UI.
One area we are struggling is in injecting commandline/node env values into these tests. Is there a way I can inject UserName and Password into TestCafe Studio tests?
I know we can do this in manually written TestCafe JS tests but I can't find any such feature in TestCafe Studio. Any example would be greatly appreciated.
I would like to inject these username and password into basic auth as well as html form based page.

You can put the user name and password into a file:
{
"userName": "user_1",
"password": "qwerty"
}
Then, use the Run TestCafe Script action to read them from it and log in:
If you need to log in before each test, put this action into Before Each hook in your fixture.

Related

How to run Selenium tests against local code?

I am using Specflow, Selenium in my current project. When I want to run my test cases I start my current project and then in my Appsetting json file I have set url like
"baseURL": {
"url": "http://localhost:5000/mypage.aspx"
}
So everytime I need to run my tests, first I need to run my server. I can't run my tests in Pipeline because the URL will be different. Is there any way that my project run the server automatically and then get the url of the server so the tests point to the current branch url?

using Webdriverio service, when running as script (no test)

I wrote a webdriver.io script for scrapping a website.
The way to start such script is by running it through node command i.e.:
node my-webdriverio.js
I want to install some Webdriverio services, specifically:
https://webdriver.io/docs/devtools-service/#cdp-command for using the CDP protocol in my script.
The problem is that the only way to register a service is by setting it into wdio.conf.js file like this:
export.config = {
// ...
services: ['devtools'],
// ...
};
the problem is that for using this method you must run it as a test (i.e. npx wdio wdio.conf.js)
but because I am using the "run in a script" option, I can't find any way to register a service
https://webdriver.io/docs/gettingstarted#run-in-a-script
and web I am trying to check if I have the cdp capability I am getting undefined:
console.log(typeof browser.cdp); // undefined
So my question is, how can I register a service, or even better how can I use the 'devtool' service when running Webdriverio as a script?

How to run my serenity feature, providing command line options(login credentials) to the program?

My serenity project feature is working perfectly, by running maven project by using
mvn clean verify
But our leadership is against keeping login credentials(userId, password) in the feature file or any external properties file. Only supplying them in the command line like
mvn exec:java -Dexec.mainClass="com.module.test.Main" -Dexec.args="arg0 arg1 arg2"
But in Serenity, there is no Main.java file with main() method. Then
how do I invoke my serenity feature file to run using Maven with the provided 2 arguments ?
Your suggestions are highly appreciated,
First off, your company is doing the right thing. Sensitive data should never be committed to code. If it is then anybody who has access to the code has access to everything.
Serenity allows parameters to be passed at runtime, e.g.
mvn clean verify -DUSERNAME=bob -DPASSWORD=mysupersecurepassword
This will pass the values into the serenity runner. Serenity then provides a utility to read in these values using SystemEnvironmentVariables.createEnvironmentVariables, e.g.
EnvironmentVariables envs = SystemEnvironmentVariables.createEnvironmentVariables();
String username = env.getProperty("USERNAME");
String password = env.getProperty("PASSWORD");

Starting protractor execution from a selenium session

How can we use protractor with an existing selenium browser session rather than always create a new one. If I have started up a selenium browser session, run some tests in there, and exported the session ID into the environment conf file in protractor or in some other way made it available, it would be nice to be able to configure protractor in the normal way (e.g. using an option in the protractor configuration file) to access this session.
I would need to start a protractor execution in the middle of a selenium execution, do some test, and come back to selenium execution. Something like pseudo-code snippet would really help.
You'll need to session id from the launched browser. You should be able to get it from the http://localhost:4444/wd/hub/static/resource/hub.html. So let's say this session id is '12345', you have two options, you could pass it as a command line or via the configuration file.
command line
protractor protractor.conf.js --seleniumSessionId=12345
configuration file
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumSessionId: '12345',
...
}
After you have set the selenium session id, you should be able to use the browser session. An example of this being exercised is: https://github.com/angular/protractor/blob/master/scripts/driverProviderAttachSession.js
If you would like to read more about it, I also have a medium post about this feature that I might have worked on: https://medium.com/#cnishina/attaching-a-protractor-test-to-an-existing-selenium-session-931196936ae2

Display selenese-runner results in Jenkins

As I am implementing an automated way to GUI test our webapplication with selenium I ran into some issues.
I am using selenese-runner to execute our Selenium test suites, created with Selenium IDE as a post build action in Jenkins.
This works perfeclty fine, as the build fails when something is wrong, and the build succeeds if all tests are passed. And the results are stored on a per build basis as HTML files, generated be selenese-runner.
My problem is however, that I seem to be unable to find a way, how to display these results in the respective jenkins build.
Does anyone have an idea how to solve this issue. Or maybe I am on the wrong path at all?
Your help is highly appreciated!
I believe the JUnit plugin should do what you want, but it doesn't work for me.
My config uses this shell script to run the tests (you can see the names of all my test suites):
/usr/bin/Xvfb &
export DISPLAY=localhost:0.0
cd ${WORKSPACE}
java -jar ./test/selenium/bin/selenese-runner.jar --baseurl http://${testenvironment} --screenshot-on-fail ./seleniumResults/ --html-result ./seleniumResults/ ./test/selenium/Search_TestSuite.html ./test/selenium/Admin_RegisteredUser_Suite.html ./test/selenium/Admin_InternalUser_Suite.html ./test/selenium/PortfolioAgency_Suite.html ./test/selenium/FOAdmin_Suite.html ./test/selenium/PublicWebsite_Suite.html ./test/selenium/SystemAdmin_Content_Suite.html ./test/selenium/SystemAdmin_MetaData_Suite.html
killall Xvfb
And I can see the result of the most recent test (you can see the name of my jenkins task folder)
http://<JENKINS.MY.COMPANY>/job/seleniumRegressionTest/ws/seleniumResults/index.html
Earlier tests are all saved on the Jenkins server, so I can view them if I need to.