selenium webdriver Grid - java

hi i am using selenium webdriver. i have to connect system and i phone for the testing
when i connect its not opening the other system, i am using chrome 38 and ie 10
i am getting stuct, please provide me your answer. check the code
if(browser.equalsIgnoreCase("Internet Explorer")){
caps = DesiredCapabilities.internetExplorer();
}
if(browser.equalsIgnoreCase("chrome")){
//System.setProperty("webdriver.chrome.driver","/10.187.143.46/C:/chr/chromedriver.exe");
//driver=new RemoteWebDriver(new URL("http://10.187.143.46:6767/wd/hub"),caps);
//ChromeDriver driver = new ChromeDriver();
// driver.get("http:\\www.google.com");
System.setProperty("webdriver.chrome.driver","\\10.187.143.46\\c$\\Users\\rr188182\\Desktop\\chromedriver.exe");
caps=DesiredCapabilities.chrome();
}
//Version
caps.setVersion(i);
driver1=new RemoteWebDriver(new URL("http://10.187.143.89:6767/wd/hub"),caps);
driver1.get("http://www.google.com");
driver2=new RemoteWebDriver(new URL("http://10.187.143.165:6767/wd/hub"),caps);
driver2.get("http://www.google.com");
driver3=new RemoteWebDriver(new URL("http://10.187.143.25:6767/wd/hub"),caps);
driver3.get("http://www.google.com");
driver4=new RemoteWebDriver(new URL("http://10.187.143.46:5555/wd/hub"),caps);
driver4.get("http://www.google.com");
driver5=new RemoteWebDriver(new URL("http://10.187.143.163:6767/wd/hub"),caps);
driver5.get("http://www.google.com");
public static void main(String[] args) throws MalformedURLException {
GridConcept gr=new GridConcept();
//gr.setup("WINDOWS", "internet explorer", "11","http://www.google.com");
...
}
if i provide ie and firefox the browser is opening but the next line is not excuting, if i use chrome it shows error as valid path. please provide your comments. Thanks in advance

Related

Switch Driver from chrome to electron with java and Selenium

I am currently testing my application using chrome driver, but for one test I need to select a link to then open an electron app, after this i am unable to interact after the op up window has appeared. Is it possible to switch over to the electron app after ive launch the chromedriver?
My driver class looks like this:
public static WebDriver startDriver() {
String projectLocation = System.getProperty("user.dir");
// add in elements for logging into the mobile application also - Android and
// iOS.
if (OSValidator.isMac()) {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_mac");
} else if (OSValidator.isWindows()) {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver.exe");
} else {
System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_linux");
}
if (System.getProperty("app.env") != null) { // If coming from Jenkins/Maven goal..
// This is for logging results. Added when investigating crashes on chrome driver. Can be disabled when not needed. 26/03/2020
System.setProperty("webdriver.chrome.verboseLogging", "true");
}
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--window-size=1920x1080");
options.addArguments("--disable-cache");
//options.addArguments("--headless");
options.addArguments("--disable-application-cache");
options.addArguments("--disk-cache-size=0");
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--dns-prefetch-disable");
options.addArguments("--disable-notifications");
options.addArguments("disable-infobars");
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
//options.addArguments("--no-sandbox"); // Bypass OS security model
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
driver = new ChromeDriver(options);
//--------------------
driver.manage().window().maximize();
return driver;
}
You need to instantiate WebDriver with the path to Electron as the binary location.
https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-Using-a-Chrome-executable-in-a-non-standard-location

How to set Chrome Options when using WebDriverManager?

I'm using Web driver manager to setup chrome driver. When setting up the driver I want to add some chrome options? How can I do it when using web driver manager?
I checked the WebDriverManager API but couldn't find any clue..
As of WebDriverManager 5.x you can instantiate the webDriver directly via the WebDriverManager builder with additional capabilities this way (in java) :
WebDriver driver;
//...
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
//...
//chromeOptions.addArguments(<another-option>);
//...
driver = WebDriverManager.chromedriver().capabilities(chromeOptions).create();
The capabilities method take a Capabilities as param.
Lucky we are, ChromeOptions implements the Capabilities interface.
public void WebDriverManagerTest()
{
//setup the chromedriver using WebDriverManager
WebDriverManager.chromedriver().setup();
//Create Chrome Options
ChromeOptions option = new ChromeOptions();
option.addArguments("--test-type");
option.addArguments("--disable-popup-bloacking");
DesiredCapabilities chrome = DesiredCapabilities.chrome();
chrome.setJavascriptEnabled(true);
option.setCapability(ChromeOptions.CAPABILITY, option);
//Create driver object for Chrome
WebDriver driver = new ChromeDriver(option);
//Navigate to a URL
driver.get("http://toolsqa.com");
//quit the browser
driver.quit();
}
Found the answer.. Check above!
This is the example code:
public class Test1{
#Test
public void WebDriverManagerTest()
{
//setup the chromedriver using WebDriverManager
WebDriverManager.chromedriver().setup();
//Create driver object for Chrome
WebDriver driver = new ChromeDriver();
//Navigate to a URL
driver.get("http://toolsqa.com");
//quit the browser
driver.quit();
}
}
from https://pypi.org/project/webdriver-manager/, pass it in after .install()
from selenium import webdriver
from webdriver_manager.opera import OperaDriverManager
options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.binary_location = "C:\\Users\\USERNAME\\FOLDERLOCATION\\Opera\\VERSION\\opera.exe"
driver = webdriver.Opera(executable_path=OperaDriverManager().install(), options=options)

IE goes to http://localhost:36559/ with message "This is the initial start page for the WebDriver server"

I am trying to launch IE but nothing happens with Selenium Java code below:
protected WebDriver ieBrowserSetUp() throws Exception {
// Read the properties file
Properties prop = getProperties();
System.setProperty("webdriver.ie.driver", prop.getProperty("IEDriverPath"));
driver = new InternetExplorerDriver();
driver.navigate().to("https://www.google.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "");
WebDriver driver= new InternetExplorerDriver(caps);
System.out.println("Internet Explorer Browser Setup Done Successfully");
return driver;
}
It is working fine with the Firefox and Chrome Webdriver. I saw in one of the posts the Protected Mode Settings needs to be changed. Is there a workaround as the settings is disabled at work considering I am not a Windows admin. The path is pointed to IEDriverServer.exe I downloaded instead of the "Windows-installed-and-defaulted" IE application.
I solved it with this:
System.setProperty("webdriver.ie.driver", prop.getProperty("IEDriverPath"));
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); //disable protected mode settings
caps.setCapability("initialBrowserUrl", url);
driver = new InternetExplorerDriver(caps);

Selenium Webdriver 3- URL is not getting entered into the Firefox Browser

Windows 10 - 32 bit
Selenium Version:
3.0.0 beta 3
Browser:
Firefox 48.02
Eclipse Luna 32 bit
package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MyClass {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty "webdriver.firefox.marionette","D:\\Selenium\\geckodriver.exe");
//System.setProperty("webdriver.gecko.driver","D:\\Selenium\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Firefox and direct it to the Base URL
driver.get(baseUrl);
// get the actual value of the title
actualTitle = driver.getTitle();
/*
* compare the actual title of the page witht the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}
}
Error:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
les":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"1.5","maxVersion":"9.9"}],"targetPlatforms":[],"multiprocessCompatible":false,"signedState":0,"seen":true}
This kind of issues are coming in selenium 3.0 beta version.
If you are using using Selenium Standalone jar then you have to pass marionette as capabilities and initialize FirefoxDriver as follows:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
Tried with geckodriver v 0.10.0.
String driverPath = "<path to gecko driver executable>";
public WebDriver driver;
public void launchBrowser() {
System.out.println("launching firefox browser");
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
driver = new FirefoxDriver();
}

Swipe and Hide comments missing in appium

I am new to appium.I would like to use driver.hideKeyboard() and drive.swipe() comments in appium.However when I try to use these comments in eclipse,it is thorowing error as
The method swipe() is undefined for the type WebDriver
Hide also I am getting same error.I think I need to import something in the drive.Could you please guide me what I need to do?
public void Appium() throws MalformedURLException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
Change your driver type to AppiumDriver. Like this:
AppiumDriver driver;
and then
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
I have tried following.It is working fine.
AppiumDriver driver;
{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}
public void()
{
driver.hideKeyboard();
}
Above appium driver I am able to get swipe and hide functions.

Categories

Resources