Running Selenium scripts on Bluemix - selenium

I am completely new to testing and Bluemix. As per my requirement, I need to run Selenium scripts on Bluemix. I am using Automated Accessibility Tester service in Bluemix for running Selenium scripts. I have added the service to my space and added the aat.jar and the Tool Configuration JSON file to my working directory. I have added some scripts to my test case for running on remote server. However, I am getting the following error message:
error Message: setEnabledIds INFO: Enabled Rulesets: IBM_DCP080115
FAILED CONFIGURATION: #BeforeClass setUp
org.openqa.selenium.remote.UnreachableBrowserException: Could not
start a new session. Possible causes are invalid address of the remote
server or browser start-up failure.
This is the script that I have added:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ComplianceConfig config = new ComplianceConfig(new String[] { "IBM_DCP080115" });
driver = ComplianceDriverRemote.init(config, capabilities);
I am getting an error at driver = ComplianceDriverRemote.init(config, capabilities);
For running test cases on Bluemix, I am following this link: https://console.ng.bluemix.net/docs/services/ecsdashboard/index.html

Related

How to get details of on which localhost karate UI test are running

I am running a UI test in karate where I need to fetch the details of local host where test are running in karate, earlier I was using selenium to the same task with the following code
ChromeOptions chromeOptions = new ChromeOptions();
WebDriverManager.chromedriver().setup();
ChromeDriver driver = new ChromeDriver(chromeOptions);
HttpCommandExecutor executor = (HttpCommandExecutor) driver.getCommandExecutor();
URL url = executor.getAddressOfRemoteServer();
And this url was returning
http://localhost:7150
Is there way to get these details in karate framework for UI tests.
I am able to fetch the port number from karate web driver
* def opt = driver.getOptions()
* def port = opt.port
And then appending to string "http://localhost:"+port which solves the problem.

The proxy moz-proxy://host:port is requesting a username and password. The site says: “LDAP”:

I have Integrated the Selenium with JMeter to perform Performance Test, For this I have used Firefox driver Cofig and gecko driver. Script is executing successfully in local window machine But when trying to execute it on Linux server it giving the following error.
"The proxy moz-proxy://host:port is requesting a username and password. The site says: “LDAP”:"
Note:
gecko driver is compatible with Firefox version.
username and password passed while setting proxy on server, and also through JMeter command.
It looks like you're behind a corporate proxy server which requires authentication and unfortunately this is not something you can bypass using Firefox Driver Config
You will need to switch to JSR223 Sampler with Groovy language and instantiate the browser manually providing the proxy host/port/username/password/etc. Take a look at Proxy class JavaDoc
Example code:
import org.openqa.selenium.Proxy
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
Proxy proxy = new Proxy()
proxy.setHttpProxy("http://username:password#proxy-host:proxy.port")
proxy.setSslProxy("http://username:password#proxy-host:proxy.port")
FirefoxOptions options = new FirefoxOptions()
options.setCapability("proxy", proxy)
FirefoxDriver driver = new FirefoxDriver(options)
driver.get('http://example.com')

Unable to start ChromeDriver in CI environment

I am using Selenium with ChromeDriver in .NET Core. All tests work fine locally, however fail in TeamCity with the following error:
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987#{#882}) on port 24272
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
...
OneTimeSetUp: OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:24272/
After the tests have finished, chromedriver.exe isn't terminated. There is nothing in the Windows event log or further details in the build logs, so I'm now stabbing in the dark.
I am using the following arguments, some added out of desperation:
var options = new ChromeOptions();
options.AddArgument("--headless");
options.AddArgument("--remote-debugging-port=9222");
options.AddArgument("--no-sandbox");
options.AddArgument("--no-first-run");
// See https://bugs.chromium.org/p/chromium/issues/detail?id=737678
options.AddArgument("--disable-gpu");
Driver = new ChromeDriver(options);
Interestingly, the remote debugging port != the port in the first error. Not sure if this means anything. The Chromedriver documentation suggests that options are added without leading --, but removing this doesn't seem to have any effect.
FWIW the TeamCity agent is running as a local Windows service account on Windows Server 2008 R2 (yes, I know).

cannot get to Selenium Proxy when setting up through BrowserMob

I am able to create a Selenium proxy using BrowserMob everything work well on my my local PC. When I run the same code on a server (Windows Server 2008 R2 Standard) it errors our "cannot connect to tunnel".
I have tried different combinations of Chrome swithes like --ignore-certificate-errors,--user-data-dir=C:/temp/insecurechrome,--ignore-certificate-errors. I have ensured that .setTrustAllServer(true) is set. I have tried adjusting the Windows Firewal without any effect.
I will add my code I am using, however, it does work on my local PC, yet not on the server. I am hoping someone can suggest other setting on the server I can changer or something in my code I may have missed.
I first get a Chrome Browser message: wating for Proxy Tunnel. Several seconds later (15-20). I get the error: ERR_TUNNEL_CONNECTION_FAILED.
browserMobProxyServer = new BrowserMobProxyServer();
browserMobProxyServer.setTrustAllServers(true);
browserMobProxyServer.start(0);
port = browserMobProxyServer.getPort();
seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxyServer);
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server","--ignore-certificate-errors","--user-data-dir=C:/temp/insecurechrome");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
PropertyConfigurator.configure("./resources/properties/log4j.properties");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
desiredCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
//desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); //Has no effect
driverService = new ChromeDriverService.Builder().usingDriverExecutable(new File("./resources/driver/chromedriver.exe")).usingPort(Integer.parseInt(portRequested)).build();
driverService.start();
return new ChromeDriver((ChromeDriverService)driverService, desiredCapabilities);
I was able to figure out my own issue. There was an existing corporate proxy that was intercepting the traffic. This proxy has different protocols for servers and for users. When running on my PC it ran fine. When running my program on a server I needed to address proxy forwarding or chaining. I accomplished this by adding the below lines to my above code:
import java.net.InetSocketAddress;
...
...
InetSocketAddress x = new InetSocketAddress("proxy.example.com", 80);
browserMobProxyServer.setChainedProxy(x);

How can I block third-party scripts on Selenium tests?

My Selenium tests are being slowed by third-party scripts that are not necessary to the tests.
How can I block them? Preferably I'd like to block requests to everywhere but localhost.
Solutions offered elsewhere online are:
Block unwanted domains (e.g., *.facebook.com) by editing your hostfiles.
Route all your tests through BrowserMob which can be configured to filter requests.
Both options seemed like overkill to me. Editing the host files affects your whole system, and using BrowserMob introduces new problems.
Here's another way: Use a PAC file to configure the browser to connect to localhost directly, and attempt to connect to everything else through an unavailable proxy.
Selenium code (Java):
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.PAC);
proxy.setProxyAutoconfigUrl("http://localhost:8080/my-pac-file.pac");
capabilities.setCapability("proxy", proxy);
ChromeDriver driver = new ChromeDriver(INSTANCE, capabilities);
The PAC file:
function FindProxyForURL(url, host) {
if (host.toLowerCase() === "localhost"){
return "DIRECT"; // whitelisted
}
return "PROXY 127.0.0.1:9876"; // blocked (bad proxy)
}