Unable to compile code line "options.addarguments("--start-maximized") ", using selinum 3.0.1 and using ChromDriver_win32 latest version and eclispe Mars.. Let me know what i am missing. I am able to compile and run my test without options..
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
public class IRSLabTestCase {
WebDriver driver1= new ChromeDriver();
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized"); //--> this line not getting compiled.
driver1 = new ChromeDriver(options);'
}
It wont work because you can only initialize members in a class.
To do operations on them you have to put it in a function or do those in a constructor.
You are initializing driver1 object twice .You have to learn java basics.Else you can't proceed further.
You can do like below.
public class IRSLabTestCase {
WebDriver driver1;
ChromeOptions options = new ChromeOptions();
public IRSLabTestCase(){
options.addArguments("--start-maximized");
driver1 = new ChromeDriver(options);'
}
}
Instead of chrome options you should try this:
ChromeDriver driver;
driver=new ChromeDriver();
driver.manage().window().maximize();
or
ChromeOptionsoptions =new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
Related
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
public class torr1 {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette",
"C:\\Users\\ghorh\\Documents\\selenium-bazinga\\Drivers\\geckodriver.exe");
String torPath = "C:\\Users\\ghorh\\Desktop\\Tor Browser\\Browser\\firefox.exe";
String profilePath = "C:\\Users\\ghorh\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default";
File torProfileDir = new File(profilePath);
FirefoxBinary binary = new FirefoxBinary(new File(torPath));
FirefoxProfile torProfile = new FirefoxProfile(torProfileDir);
FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);
options.setProfile(torProfile);
options.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
WebDriver driver = new FirefoxDriver(options);
driver.get("http://google.co.in");
}
}
I have tried the above code so far but getting message: 'tor failed to start'. Could somebody please help on what changes are required for the above code.
You are trying to use FireFox driver.
Try use TorBrowserDriver as specified in its readme: https://github.com/webfp/tor-browser-selenium
Or if you want to use firefox - use GeckoDriver that can be downloaded from the next link:
https://github.com/mozilla/geckodriver/releases/tag/v0.26.0
I would like to seek help if there is a possible way / code to capture a screenshot under Krypton platform that uses JAVA selenium. I'm having trouble in terms of it's standardization. Thanks!
var driver = new ChromeDriver()
driver.get("https://login.bws.birst.com/login.html/")
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"))
As per the screenshots there seems to be some discrepency with the imports/Classes. Further to keep things simpler create destination folder within the Project Scope e.g. the Screenshots directory below:
To capture a screenshot using Java you can use the following solution:
Code Block:
package screenShot;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class takesScreenshot {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://login.bws.birst.com/login.html/");
new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("Birst"));
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(".\\Screenshots\\Mads_Cruz_screenshot.png"));
}
}
Captured Image:
I am trying to open local files with Selenium. With the code below, Firefox is opening, but I have the error org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start..
File gecko = new File("resources/geckodriver64.exe");
System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());
FirefoxOptions capabilities = new FirefoxOptions();
capabilities.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("file:///C:/example/myfile.pdf");
Can someone help me ? I couldn't find anything on the internet.
We have now come to the part where you will see how you can use GeckoDriver to launch Firefox. You will first need to download GeckoDriver and then set its path. There are three different ways to use GeckoDriver with Selenium 3:
With setting system properties in the test
With setting system properties by Environment Variable
With setting up Browser Desired Capabilities
Download Gecko Driver:-
1- Gecko Driver different versions can be downloaded from Github. I suggest you to use the latest version.
Set System Properties for Gecko Driver:-
Code to set the System properties is System.setProperty(“webdriver.gecko.driver”,”Path to geckodriver.exe”);
The complete program to launch the GeckoDriver will be like this:
package seleniumPrograms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "D:\\\\XXXX\\trunk\\Library\\drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.toolsqa.com");
Thread.sleep(5000);
driver.quit();
}
}
Check Below answer. This is working solution on my machine. Please check your firefox version too.
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class geckodriver {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\username\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
Thread.sleep(5000);
// DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// capabilities.setCapability("marionette", true);
//
// WebDriver driver = new FirefoxDriver(capabilities);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setVersion("your firefox version");
capabilities.setPlatform(Platform.WINDOWS);
capabilities.setCapability("marionette", false);
WebDriver driver = new FireFoxDriver(capabilities);
driver.get("http://www.google.com");
Thread.sleep(5000);
driver.quit();
}}
Can you try below code ?
package seleniumPrograms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.google.com");
Thread.sleep(5000);
driver.quit();
}
package AppiumTest;
import java.net.URL;
import java.net.MalformedURLException;
import org.testng.annotations.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.CapabilityType;
import io.appium.java_client.ios.IOSDriver;
public class TestIOSSafariBrowser{
#Test
public void startBrowser() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","iPhone 8");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "11.4.1");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "safari");
IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("http://www.google.com");
System.out.println("Page title is " + driver.getTitle());
}
}
I'm relatively new to using Selenium and Appium.
I'm trying to open Safari to access Google through Xcode and Appium. When I instantiate IOSDriver as driver down below, IOSDriver does not allow me to pass in a DesiredCapabilities object (capabilities), instead expecting me to pass a Capabilities object. How would I try to open Safari and access the Google homepage if I use the Capabilities object instead of DesiredCapabilities, or is there another way to go about this?
I am using this code to integrate the browser mob proxy with maven dependency
net.lightbody.bmp browsermob-core 2.1.5
its not capturing the network requests at all, I am getting this kind of har file:
{
"log":{
"version":"1.2",
"creator":{
"name":"BrowserMob Proxy",
"version":"2.1.0-beta-6-littleproxy",
"comment":""
},
"pages":[
{
"id":"11",
"startedDateTime":"2017-10-26T17:28:42.501+05:30",
"title":"11",
"pageTimings":{
"comment":""
},
"comment":""
}
],
"entries":[],
"comment":""
}
}
package lenskart.tests;
import java.io.File;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.mitm.manager.ImpersonatingMitmManager;
import net.lightbody.bmp.proxy.CaptureType;
public class ProxyTestClass {
#Test
public static void main() throws Exception {
// TODO Auto-generated method stub
BrowserMobProxyServer browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.setTrustAllServers(true);
browserMobProxy.setMitmManager(ImpersonatingMitmManager.builder().trustAllServers(true).build());
browserMobProxy.start(0);
System.out.println("Port Started On: " + browserMobProxy.getPort());
System.setProperty("webdriver.chrome.driver", "/Users/pankaj.katiyar/Desktop/Automation/Lenskart_Automation/tpt/drivers/chromedriver");
browserMobProxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT, CaptureType.RESPONSE_HEADERS);
WebDriver driver = getDriver_CapProxy(browserMobProxy);
driver.get("http://www.lenskart.com");
driver.navigate().to("http://www.google.com");
driver.quit();
browserMobProxy.stop();
browserMobProxy.newHar("11");
browserMobProxy.getHar().writeTo(new File("/Users/pankaj.katiyar/Desktop/Automation/Lenskart_Automation/har"));
;
System.out.println("Loaded browser ");
}
public static WebDriver getDriver_CapProxy(BrowserMobProxyServer browserMobProxy) throws UnknownHostException {
Proxy proxy = ClientUtil.createSeleniumProxy(browserMobProxy);
proxy.setHttpProxy("localhost:" + browserMobProxy.getPort());
DesiredCapabilities cap = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
return driver;
}
}
There's two issues with your code.
First the selenium proxy is assigned to the capabilities, but the instance is never used. So either assign the options to the capabilities, or directly assign the selenium proxy to the options:
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy);
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
options.setCapability(CapabilityType.PROXY, seleniumProxy);
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Second, you are calling browserMobProxy.newHar at the end of the recording when it should be at the beginning:
browserMobProxy.newHar("11");
driver.get("http://www.lenskart.com");
driver.navigate().to("http://www.google.com");
browserMobProxy.getHar().writeTo(new File("/Users/pankaj.katiyar/Desktop/Automation/Lenskart_Automation/har"));
driver.quit();
browserMobProxy.stop();
I ran your code and only two changes you need are, change
WebDriver driver = new ChromeDriver(options);
to
WebDriver driver = new ChromeDriver(cap);
And move browserMobProxy.newHar("11"); before the navigate
browserMobProxy.newHar("11");
driver.get("http://www.lenskart.com");
Rest all is fine in your code. Once you do that Har is generated fine as shown in below screenshot