Run MARIONETTE instead gecko - java

I'm trying to run selenium with marionette, but after run nothing showing
#Before
public void setup() {
FirefoxOptions options= new FirefoxOptions();
options.setCapability(FirefoxDriver.MARIONETTE, false);
driver = new FirefoxDriver(options);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("www.google.com");
}
#Test
public void testLoginAndHomePage() {
login = new LoginPage(driver);
String loginPageTitle = login.getLoginTitle();
Assert.assertTrue(loginPageTitle.contains("GOOGLE"));
System.out.println("Test Passed");
}
Is it possible to run marionette without System.setProperty() ?

Related

Cannot inject #Test annotated Method with [class io.appium.java_client.android.AndroidDriver]

Im trying run my TestNG test and I am getting this error:
Cannot inject #Test annotated Method [Test1] with [class io.appium.java_client.android.AndroidDriver].
Dont know what must do. I'm using Appium whit TestNG.
#Listeners(ExtentITestListenerAdapter.class)
public class TestNG {
public AppiumDriver <AndroidElement>driver;
#Test
public void Test1(AndroidDriver driver) {
MobileElement el1 = (MobileElement) driver.findElementById("skip_button");
el1.click();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(725, 993)).perform();
touchAction.tap(new PointOption().withCoordinates(293, 1005)).perform();
touchAction.tap(new PointOption().withCoordinates(1175, 1531)).perform();
touchAction.tap(new PointOption().withCoordinates(1166, 2029)).perform();
touchAction.tap(new PointOption().withCoordinates(763, 2036)).perform();
MobileElement el2 = (MobileElement) driver.findElementById("continue_button");
el2.click();
}
#BeforeClass
public void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "Android");
desiredCapabilities.setCapability("deviceName", "Pixel_4_2");
desiredCapabilities.setCapability("automationName", "UiAutomator2");
desiredCapabilities.setCapability("udid", "emulator-5554");
desiredCapabilities.setCapability("app", "C:\\Users\\Diego\\Desktop\\flow-music-develop-dev-debug-v0.11.0-SNAPSHOT-209.apk");
desiredCapabilities.setCapability("ensureWebviewsHavePages", true);
URL remoteUrl = new URL("http://localhost:4723/wd/hub");
driver = new AndroidDriver(remoteUrl, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#After
public void tearDown() {
driver.quit();
}
}
If you want to use parameters in test method, you need to provide the DataProvider or using Parameter from file testng.xml
Link to docs: https://testng.org/doc/documentation-main.html#parameters
In this case, just remove the parameter of method, i.e public void Test1(AndroidDriver driver) -> public void Test1()
I found the solution
#BeforeMethod
public void setUp() throws Exception{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "Android");
desiredCapabilities.setCapability("deviceName", "Pixel_4_2");
desiredCapabilities.setCapability("automationName", "UiAutomator2");
desiredCapabilities.setCapability("udid", "emulator-5554");
desiredCapabilities.setCapability("app", "C:\\Users\\Diego\\Desktop\\flow-music-develop-dev-debug-v0.11.0-SNAPSHOT-209.apk");
desiredCapabilities.setCapability("ensureWebviewsHavePages", true);
URL remoteUrl = new URL("http://localhost:4723/wd/hub");
driver = new AndroidDriver(remoteUrl, desiredCapabilities);
String sessionId = driver.getSessionId().toString();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
I declare this method using the #BeforeMethod, if you seed this method contain this
"driver = new AndroidDriver(remoteUrl, desiredCapabilities);"
Using this i havent the problem.
Ty all

java.lang.NullPointerException when using webdriver manager selenium java

While using selenium with java, WebdriverManager is not running and the below code is giving null pointer exception. I have returned the driver at end of class.
I have one ask whether should I keep the Webdriver driver as static or not.
import io.github.bonigarcia.wdm.WebDriverManager;
public class Browserselector {
public WebDriver driver;
public static Properties prop;
public WebDriver initializeDriver() throws IOException {
{
String browserName = "firefox";
System.out.println(browserName);
if (browserName.contains("Chrome")) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if (browserName.contains("IE")) {
WebDriverManager.iedriver().setup();
driver = new InternetExplorerDriver();
} else if (browserName.contains("FireFox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
} else if (browserName.contains("EDGE")) {
WebDriverManager.edgedriver().setup();
driver = new EdgeDriver();
}
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("google.com");
return driver;
}
}
Thanks for your help in advance.
you are trying to start "firefox" - but the if condition checks for "Firefox", if you want to use it like that change the following condition
browserName.contains("FireFox")
into
browserName.equalsIgnoreCase("FireFox")
I recommend you to change the nested if with a "switch" it's more readable and easy to follow/understand
Also, don't use a URL without specifying the protocol
driver.get("https://www.google.com");

Selenium: changing proxy in Firefox

i'm writing tests in selenium and want to change proxy to auto-detect in firefox, default is proxy from system settings. How to do it?
I have code below:
public class SodirRejestracja {
String baseUrl = "http://google.pl";
String driverPath= "C:\\geckodriver.exe";
WebDriver driver;
#BeforeTest
public void beforeTest() {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 2);
System.setProperty("webdriver.gecko.driver", driverPath);
driver=new FirefoxDriver(profile);
}
#Test
public void test(){
driver.get("http://google.com");
}
}
Code above is from How do I set a proxy for firefox using Selenium webdriver with Java?
but in line driver=new FirefoxDriver(profile) i get: "The constructor FirefoxDriver(FirefoxProfile) is undefined"
A sample (not tested but that compiles) that should do it
String proxyName = <yourProxyHost> + ":" + <yourProxyPort>;
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyName)
.setFtpProxy(proxyName)
.setSslProxy(proxyName);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
FirefoxOptions options = new FirefoxOptions(desiredCapabilities);
driver = new FirefoxDriver(options);
This code works
Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.AUTODETECT);
FirefoxOptions options = new FirefoxOptions();
options.setProxy(proxy);
driver = new FirefoxDriver(options);

How to launch the Chrome Postman Plugin using Selenium Webdriver

ChromeDriver driver = new ChromeDriver();
ChromeOptions options=new ChromeOptions();
options.addArguments("chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm/index.html");
driver = new ChromeDriver(options);
Tried using the above code.
You can open extension page using below code :
public class sample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "yourpath/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("chrome://extensions/");
}
}
If you want to open plugin page then user below code :
public class sample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "yourpath/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://chrome.google.com/webstore/search/postman?hl=en-US");
}
}
Note : if you have not downloaded "chromedriver" yet , then please download from HERE

Not able to run selenium script using phantomjs driver

I am new to phantomjs driver, I need to run my script in background using phantomjs headless driver.
Here is my code i am getting null-pointer exception.
currently am using selenium 2.32,testNG,phantomjs jar 1.0.3
public class PhantomjsDemo {
public WebDriver driver;
#BeforeMethod
public void setup(){
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"C:\\phantomjs-1.9.2-windows\\phantomjs.exe");
WebDriver driver = new PhantomJSDriver(caps);
driver.get("www.google.com");
}
#Test
public void google(){
driver.findElement(By.xpath("//*[#id='gbqfba']")).getText();
driver.findElement(By.xpath("//*[#id='gbqfba']")).getSize().getHeight();
driver.findElement(By.xpath("//*[#id='gbqfba']")).getSize().getWidth();
driver.findElement(By.xpath("//*[#id='gbqfba']")).click();
}
#AfterMethod
public void close(){
driver.quit();
}
}
You are not initializing your Webdriver member variable in the setup() method, but a method variable:
WebDriver driver = new PhantomJSDriver(caps);
Change it to
this.driver = new PhantomJSDriver(caps);
and the NPE should go away.

Categories

Resources