Can I install and run a chromium without any GUI on Ubuntu 16.4? - ubuntu-16.04

I have a naked Ubuntu-16.4-machine with no GUI, only the console. Can I somehow install and run chromium on this? or do I have to install a GUI to use a browser?
how would I do this?

you can't use chromium directly, but you can use selenium with python and use chromium headless. here is a sample code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.binary_location = "/usr/bin/chromium"
opts.add_argument("--headless")
opts.add_argument("--window-size=1920x1080")
driver = webdriver.Chrome(options=opts)
driver.get("https://www.google.com")
you can also capture screenshots to check the webpage:
enter driver.get_screenshot_as_file("capture.png")

Related

How to enable GPU and stop kicking off from colab when using SSH from VScode

I have been following this thread to remote in through VSCode using SSH and ngrok Configuring Google Colab Like A Pro. It works pretty good. But I have encountered two problems:
Q1. How to setup GPU from VSCode? In the Colab there is a dropdown menu, where you could select GPU to accelerate the training process. But how do we do it in VScode through SSH?
Q2. How to prevent kicking off from Colab? I have read a trick in this Configuring Google Colab Like a Pro and How to prevent Google Colab from disconnecting. But they are not intended to be used in the VScode environment through SSH. Basically it has to be run in the Colab cell.
Thanks.
I have found a hack to solve the problems you're facing [I was having the same issue too :) ]
Steps:
Go to Google Colab, create a new notebook
Run this command !export -p in a cell; you should see the list of environment variables available to the Colab environment.
Find this line in the output declare -x COLAB_GPU="0".
In another cell, run the following code:
import os
os.environ['COLAB_GPU'] = "1"
Run !export -p again, now you should see declare -x COLAB_GPU="1".
Now run !pip install colab_ssh --upgrade
After installing colab_ssh, set a secret_password and run the following code:
from colab_ssh import launch_ssh_cloudflared
launch_ssh_cloudflared(secret_password)
Follow the Client-machine configuration as shown in the output cell.
Assuming you've successfully connected your local VSCode IDE to Colab Kernel over ssh-tunnel, you should now be able to open a notebook from your GDrive and run codes that require GPU access/High-RAM.

Is this possible to configure WebStorm to start webdriver-manager to execute Protractor script?

I am using WebStorm IDE to work with Protractor. So far, I am starting webdriver-manager from command prompt and executing the script in WebStorm.
Is there a way to start and keep running webdriver-manager from WebStorm itself? If Yes, Please let me know the steps.
You can configure it as External tool in Settings | Tools | External Tools and then use menu action/assigned shortcut to start it:
If you don't like to start server manually, you can set up your protractor configuration accordingly:
If you have a standalone server installed, you can start it automatically by specifying seleniumServerJar in protractor.conf.js - see http://www.protractortest.org/#/server-setup#standalone-selenium-server, Starting the Server from a Test Script
Another option is using directConnect - see http://www.protractortest.org/#/server-setup#connecting-directly-to-browser-drivers

Do we really need to run webdriver-manager start before running protractor?

In order to run my unit tests against IE, I just run protractor without running the webdriver-manager start. According to the existing online docs (such as here), we should run selenium server before running tests on browsers except Chrome and Firefox,
Do you know how my does protractor work which doesn't need the selenium server?
There are two ways to run the protractor. As you know, first one is to provide the webdriver url in confg.js like seleniumAddress: 'http://localhost:4444/wd/hub'
In this case, you need to start the webdriver manually by using webdriver-manager start
If you do not provide this parameter in your confg.js then protractor will try to invoke webdriver instance on its own. But for the same, you need to have webdriver installed. And that is the second way.
npm install -g webdriver-manager
But by default when you install the protractor by using npm install -g protractor, protractor and webdriver-manager both are installed together.
According to the protractor github page, protractor will start a selenium server by default. As long as you've webdriver-manager updated, you don't need to run webdriver-manager start.

Configuring Protractor with WebStorm

I am new to Protractor and WebStorm.
Please help me in configuring Protractor with WebStorm and executing scripts successfully.
I did try to configure, but then it does not identify sendKeys function.
WebStorm provides no support for protractor (if you miss it, please vote for WEB-9236). But you can use Node.js Run configuration to run it. It would looks as follows:
JavaScript file: path/to/protractor
Application parameters: [options] protractor.conf.js

start ipython notebook with a particular (not default) firefox profile

When I launch ipython notebook, I want it to launch firefox but using a particular firefox profile, which is not my default firefox profile.
In my ipython profile, I have
c.NotebookApp.browser = u'/usr/bin/firefox'
and that makes sure that ipython notebook chooses firefox. However, it chooses the default firefox profile, or else the most recently used firefox profile.
From my linux terminal, I can launch my preferred ipython specific firefox profile (named ipython) like this
firefox -P --no-remote ipython
However, doing
c.NotebookApp.browser = u'/usr/bin/firefox -P --no-remote ipython'
does not work at all (ipython doesn't open firefox at all, and skips to the another browswer'), nor does starting ipython notebook like so
ipython notebook --browser 'firefox -P --no-remote ipython'
which leads to and OSError exception.
Does anyone know of a way to launch firefox with the preferred profile?
A little ugly but maybe better than nothing. I put the following into a shell script to launch firefox and ipython separately but at the same time i.e.
firefox -P ipython -no-remote
ipython notebook --no-browser
You will need to refresh the browser.
My solution uses a script to start firefox with the requested profile and makes Jupyter call it.
Create a script in e.g. /usr/local/bin/firefox-notebook with the following content:
!/bin/env sh
firefox -P notebook $#
Instruct Jupyter to use that script as a browser by adding the following in your jupyter_notebook_config.py:
import webbrowser
browser = webbrowser.Mozilla('firefox-notebook')
webbrowser.register('firefox-notebook', None, browser)
c.NotebookApp.browser = 'firefox-notebook'
You can simply add c.NotebookApp.browser = 'firefox -P notebook --new-window %s' to ~/.jupyter/jupyter_notebook_config.py. (You missed the %s. It will be replaced by the URL at which jupyter is served.)