Selenium automation test on Windows Server 2012 R2 using local host - java

I am trying to develop automation test on Amazon active Workspace, which uses Windows Server 2012 R2. I am doing it on local machine using localhost:8002. There is no internet access on the machine. So far I have following code:
package activeworkspaceprog;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class ActiveWorkspaceProg {
WebDriver driver;
JavascriptExecutor jse;
public static void main(String[] args)
{
ActiveWorkspaceProg run = new ActiveWorkspaceProg();
run.invokeBrowser();
}
public void invokeBrowser()
{
try
{
System.setProperty("webdriver.ie.driver","C:\\Users\\Administrator\\Desktop\\IEDriverServer.exe");
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
driver = new RemoteWebDriver(
new URL("https://WIN-K0E8GV2L510:8002#hub-cloud.browserstack.com/wd/hub")
,capability);
capability.setCapability(InternetExplorerDriver.
INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.get("http://localhost:8002/awc/");
}
catch( Exception e)
{
e.printStackTrace();
}
}
}
I am using Selenium Standalone Server-3.13.0 jar and IEDriverServer.exe (version - 3.13.0.0) as my WebDriver.
But, I am just getting the following error,and I am stuck.
Error:
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. Build info: version: '3.13.0',
revision: '2f0d292', time: '2018-06-25T15:32:19.891Z' System info:
host: 'WIN-K0E8GV2L510', ip: '10.0.1.252', os.name: 'Windows Server
2012 R2', os.arch: 'amd64', os.version: '6.3', java.version:
'1.8.0_171'
Any help would be appreciated.

Just to give an update on my question. I was able to solve the issue by setting the security setting of the internet explorer to be at the same level. By default, the all zones security is set at different levels. The protected mode is enabled for Internet, Local intranet and Restricted sites. However, it is not enabled for Trusted sites. So, these different levels of security setting confuses the browser, which ends up throwing an error. So, make sure they are either enabled for all or disabled for all, so that they are set at the same level. Just following code should be enough to invoke the browser:
WebDriver driver;
JavascriptExecutor jse;
public static void main(String[] args)
{
ActiveWorkspaceProg run = new ActiveWorkspaceProg();
run.invokeBrowser();
}
public void invokeBrowser()
{
try
{
System.setProperty("webdriver.ie.driver","C:\\Users\\Administrator\\Desktop\\IEDriverServer.exe");
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setCapability("ignoreZoomSetting", true);
capability.setCapability(InternetExplorerDriver.
INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.get("http://localhost:8002/awc/");
}
catch( Exception e)
{
e.printStackTrace();
}
}
}
Look the following link for further understanding
Unable to launch IE browser in selenium webdriver

Related

how to resolve this problem cannot convert from ChromeDriver to WebDriver

public static void main(String[] args) {
String browserName = "chrome";
WebDriver driver = null;
if (browserName.equalsIgnoreCase("chrome")) {
driver = new ChromeDriver();
} else if (browserName.equalsIgnoreCase("edgebrowser")) {
driver = new EdgeDriver();
i write exactly but still am getting mismatch error
rename your class
add import org.openqa.selenium.WebDriver
add property webdriver.chrome.driver
Code:
package selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
public class Gayatri {
public static String chromedriverPath = System.getProperty("user.dir") + "\\resources\\chromedriver.exe";
public static void main(String[] args) {
String browserName = "chrome";
WebDriver driver = null;
if (browserName.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", chromedriverPath);
driver = new ChromeDriver();
} else if (browserName.equalsIgnoreCase("edgebrowser")) {
driver = new EdgeDriver();
}
driver.get("https://www.stackoverflow.com");
System.out.print(driver.getTitle());
driver.quit();
}
}
Output:
Starting ChromeDriver 100.0.4896.60 (6a5d10861ce8de5fce22564658033b43cb7de047-refs/branch-heads/4896#{#875}) on port 19334
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
KvÄ› 02, 2022 8:15:46 DOP. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Stack Overflow - Where Developers Learn, Share, & Build Careers

Selenium does not respond to electron desktop app alert dialog [duplicate]

In My JavaCode , After clicking on Edit Description link a window get opens (i.e. Java Script Window) Images here 1st one gives anchor tag with attributes and 2nd one is opened window
Image 1::
Image 2:: Window image Along with Page Source here
What i need is A. Select the window open(java script) B. Enter the text into Text Area and click Ok.
control is waiting infinite # Select Window key word its not moving forward. I have to kill Control forcefully.
Here is the code
package Bala.AutoPratice.module1;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class WindowSwitch {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\bin\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//driver.manage().window().maximize();
driver.get("http://10.1.111.165/Login.aspx");
//To check if we have landed in the correct place
driver.findElement(By.id("LoginName")).sendKeys("User1");
driver.findElement(By.id("Password")).sendKeys("User1#123");
driver.findElement(By.id("LoginBtn")).click();
driver.get("http://10.1.111.165/roles.aspx");
driver.findElement(By.xpath("//*[#id=\"NewBtn\"]/span")).click();
driver.findElement(By.xpath("//*[#id=\"aspnetForm\"]/table/tbody/tr[1]/td[2]/a")).click();
String MainWindow=driver.getWindowHandle();
Set<String> s1=driver.getWindowHandles();
Iterator<String> i1=s1.iterator();
while(i1.hasNext())
{
String ChildWindow=i1.next();
if(!MainWindow.equalsIgnoreCase(ChildWindow))
{
// Switching to Child window
driver.switchTo().window(ChildWindow); // HERE IT NEVER SELECTS
driver.findElement(By.xpath("//*[#id=\"descript\"]")).sendKeys("gadddn#gmail.com");
driver.findElement(By.xpath("//*[#id=\"myform\"]/div/input[1]")).click();
// Closing the Child Window.
driver.close();
}
}
// Switching to Parent window i.e Main Window.
driver.switchTo().window(MainWindow);
driver.quit();
}
}
If i use this
Alert myAlert = new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
myAlert.sendKeys("I_am_bbk");
myAlert.accept();
I am getting this error
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'no such alert' (400 expected)
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for alert to be present (tried for 10 second(s) with 500 MILLISECONDS interval)
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'HIBAWL56712', ip: '10.158.126.17', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities
It is pretty clear from your snapshot that the window which gets opened is a JavaScript window i.e. an Alert. To enter some text into the Text Area and click Ok you can use the following block of code :
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
//other code
Alert myAlert = new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
myAlert.sendKeys("I_am_bbk");
myAlert.accept();
driver.quit();

Trying to launch firefox browser using selenium jar files in eclipse getting e

I'm trying to launch firefox browser from eclipse using selenium as I'm learning selenium.
My tutor wrote the below code but when i'M trying the same code I get this exception-
Exception in thread "main" java.lang.IllegalStateException:
The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see
Link1. The latest version can be downloaded from
Link2
Code:
package appselenium1;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
}
}
You are facing this exception, because you have not used gecko driver , which is required for launching and sending command in selenium.
You can download the latest version of gecko version from here
Try this :
package appselenium1;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A {
static WebDriver driver ;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
}
}
While you work with Selenium ver3.x, GeckoDriver ver0.21.0 and Firefox ver61.0.1, you need to download the latest GeckoDriver from mozilla/geckodriver and store it anywhere within your system. In your code you need to provide the absolute path of the GeckoDriver through the System.setProperty() line as follows:
package demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A_Firefox
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
Note: Replace the packagename (demo in this example) with your own package name.

Error in fire fox selenium web driver

Recently, bump into this issues with selenium firefox driver.
Thanks in advance
Set UP
os.name: 'Mac OS X',
os.arch: 'x86_64',
os.version: '10.12.6',
java.version: '1.8.0_131'
Firefox version 56.0.1 (64-bit)
Gecko Driver Latest 0.19.0
The error shows failed:
org.openqa.selenium.SessionNotCreatedException: Tried to run command
without establishing a connection
I tried different ways to tackle it but always come with the same error.
1. update all the selenium test driver to the latest
2. specify the directory export PATH = $PATH driverDir
My code
package automationFramework;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
public class GeckoDriver {
private static WebDriver driver;
public static int random = 0;
private String baseURL;
// #BeforeClass : Executes only once for the Test-Class.
#BeforeClass
public static void setting_SystemProperties(){
System.out.println("System Properties seting Key value.");
}
// #Before : To execute once before ever Test.
#Before
public void test_Setup(){
System.out.println("Launching Browser");
if (random == 0) {
System.out.println("Start Chrome Browser Testing ");
System.setProperty("webdriver.gecko.driver", "/Users/Fannity/Desktop/Drivers/geckodriver"); // Chrome Driver Location.
driver = new FirefoxDriver();
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("Session ID : " + ((RemoteWebDriver) driver).getSessionId() );
}
#Test
public void selenium_ScreenShot() throws IOException {
baseURL = "https://www.google.com/";
driver.get(baseURL);
System.out.println("Selenium Screen shot.");
File screenshotFile = ((RemoteWebDriver) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotFile, new File("/Users/Fannity/Desktop/JUNIT-Selenium.jpg"));
random += 1;
}
// #After : To execute once after ever Test.
#After
public void test_Cleaning(){
System.out.println("Closing Browser");
baseURL = null;
driver.close();
driver.quit();
}
// #AfterClass : Executes only once before Terminating the Test-Class.
#AfterClass
public static void clearing_SystemProperties(){
System.out.println("System Property Removing Key value.");
System.clearProperty("webdriver.gecko.driver");
}
}
ERROR
https://gist.github.com/Fenici/f82f885486de37ae110fda8d7430df6e
Your problem is here:
#After
public void test_Cleaning(){
System.out.println("Closing Browser");
baseURL = null;
driver.close();
driver.quit();
}
Try only with close().
Explanation here.
We generally get this , if we use driver.close() and driver.quit() together so it would be better if you remove driver.close();
public void test_Cleaning(){
System.out.println("Closing Browser");
baseURL = null;
driver.quit();
}

BrowserMob is not allowing https connections to open via Selenium

I am trying to capture https traffic using selenium but is not able to capture it. Http traffic is captured correctly but having issue with https traffic. Get the same message on both chrome and firefox
'Oops.
Something went wrong.
Firefox can't load this page for some reason.'
package com.quadanalytix.selenium;
import org.browsermob.proxy.ProxyServer;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Test2 {
public static void main(String[] args) throws Exception {
ProxyServer server = new ProxyServer(4446);
server.start();
// get the Selenium proxy object
Proxy proxy = new Proxy();
proxy.setSslProxy("localhost:4446");
proxy.setHttpProxy("localhost:4446");
//captures the moouse movements and navigations
server.setCaptureHeaders(true);
server.setCaptureContent(true);
// configure it as a desired capability
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver", "/Users/tarunaggarwal/Desktop/Selenium/ChromeDriver");
// start the browser up
WebDriver driver = new ChromeDriver(capabilities);
server.newHar("gmail");
driver.get("https://www.gmail.com/");
server.stop();
driver.quit();
}
}
Why are you creating a new Java proxy object instead of the follwing?
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy());
Can you try the following with chrome:
ChromeOptions options = new ChromeOptions()
options.addArguments("--proxy-server=localhost:4446")
driver = new ChromeDriver(options)

Categories

Resources