How to open a url on browser using expect script? - bash

My bash script when runs produce a URL (basically a login URL to azure), wherein the user has to login to Azure account. I want to automate this using expect script so that the URL automatically opens up in the browser.
This is the kind of URL that my shell script produces :
Please log into Microsoft Azure
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ******* to authenticate.

Depending on JS usage on the webpage, you will not be able to login using expect / curl.
You might want to consider using selenium with firefox, which can record a standard login session and replay it later.
You might then fun firefox headless with selenium to login.

Related

Can I close the current browser window and give the focus back to the application that had it before the tab opened?

I'm developing a shell based application. At some point I need to get an oauth token. To do so I start a local server, and open a tab in a browser that'll redirect to the local url once the token is obtained. This seems quite standard, for instance here's Okta's story.
I would like the user to automatically come back to the shell once the token is obtained and the tab is closed. Can I do so?
Start a local server from my shell based program, listening on localhost:3001:
const app = express();
app.get('/', (req, res) => {
res.send('<!DOCTYPE html><html><body><script>window.close();</script></body></html>');
server?.close();
token = req.query.token;
});
server = app.listen(3001);
Open a webpage that'll communicate the token back to my local server:
open http://mywebsite.com/auth/redirect_url=localhost:3001
In the local server, respond to any request with window.close(); (see above)
This works fine in term of getting the token in the shell from the browser. However once the above is done, the user is faced with their default browser on the last tab that was opened before the one launched from the shell, instead of the shell.
Can I do the same and yield the focus back to the shell when closing the tab?
You probably would use in-context launch technique to start(navigate to) the oauth login session. After login completed, you can navigate back to your session.

Why jx install runs chrome to get the admin token?

When I run jx install I get those error messages
Attempting to find the Jenkins API Token with the browser in headless mode...using url http://jenkins.jx.35.205.149.20.nip.io/me/configure
unable to automatically find API token with chromedp using URL http://jenkins.jx.35.205.149.20.nip.io/me/configure
retrying after error:Running in batch mode and no default api token found
Unfortunatly, I'm running those install script from an Ansible docker container. As a consequence, I have no chrome installed in container (neither do I have an X environment and window manager).
So why is this token retrieved ? And is there a way to set it "by hand" (through another jx command, as an example) ?
there’s currently no other way with Jenkins to get an API token until we move to ephemeral / one shot masters rather than static masters.
We could disable the use of Chrome though? If it cannot use Chrome to get the API token the code asks you to visit the URL and copy/paste the api token from the Jenkins console

JMeter proxy is blocking the login

I am trying to record a test script with JMeter for an internal website hosted on company intranet. I can record only till navigation of the login page, submitting username/password, and click on login button. The login page reloads all the time. Nothing else happens.
Steps to reproduce ->
1) I started the JMTeter HTTP Test script recorder
2) I changed the browser settings to point it to the proxy.
3) Navigated to login page, keyed in username/password, and clicked login
4) The login page reloads, nothing else happens.
I tried it on all the browser. It's same everywhere. I recorded testes on gmail and facebook successfully. I did not face any issue there for navigation. Please help me. Is it an issue with the server where the site is hosted?
What kind of login authentication that you used in your internal website? Is it the same authentication as gmail or facebook (using login form, then compare it to database)? Or is it Active Directory User (windows account) authentication (usually, there is browser popup to enter username and password).
You can try this:
Start the JMTeter HTTP Test script recorder
changed the browser settings to point it to the proxy
Navigate to login page, keyed in username/password, and clicked login. From this point, you will have sampler for login step
changed the browser settings to not using JMeter proxy
Navigate to login page, keyed in username/password, and clicked login. It should be working
changed the browser settings to point it to the proxy again
Do the rest recording normally to get the rest scenarios.
I hope that will help you.

JMeter: Can't sign in to the app that uses Google Auth

I wanna create a test in JMeter for an web app that use google auth as a login.
So basically user sees the app login button on login page, clicks it --> navigates to google login page where he should set an email, a password, and click Sign In button.
I have stucked on "Sign In" step that is the following post request:
https://accounts.google.com/ServiceLoginAuth
all parameters are easy to extract except for "bgresponse".
when user navigates to google sign in page, bgresponse value = js_disabled that is not default and cannot be used for the post request.
it is set with a real value when user hits Sign in button.
thus, I can't extract the correct bgresponse value value as a post processor of the request that leads to google sign in page.
Any ideas how can I sign in to google via JMeter?
Please help.
TIA
Anna
Google supports oauth 2.0
https://developers.google.com/accounts/
so I think you can expand your question to JMeter and oauth 2.0
Here are a few resources:
https://malalanayake.wordpress.com/tag/oauth-2-0/
how to config apache jmeter 2.6 oauth 2.0
I think than you can use WebDriver Sampler available via plugin (you'll need WebDriver Set). This extension allows Selenium tests to be executed from JMeter and you can launch a real browser to perform Google authentication and obtain permanent OAuth token from callback page.
You won't be able to do any performance testing with the WebDriver Sampler (don't attempt to use it with more than 1 thread), but it'll be quite enough for successful OAuth 3-step process.

Can we handle OS pop-up using "gem sikuli" in selenium script

When I hit url in browser it gives windows authentication pop-up and we need to enter proper username and password into that then only it will give home page of that site.
It is not able to handle windows pop-up using Selenium-WebDriver
I was trying to handle that pop-up using gem sikuli code inside selenium script but it is giving error as
Timeout::Error: execution expired
OS pop ups cannot be handled using Selenium Web Driver , however there are numerous other frameworks that can handle it. This is for a upload window , thus should work for your scenario too.
This is what I use in C#
driver.get("http://LOGIN:PASSWORD#localhost:8080/myApp/")
LOGIN> -> username which you need pass for authentication
PASSWORD> -> password which you need pass for authentication
After # put your URL.
Don't forget to put / at the end of the URL, At-least for firefox.

Resources