while running the below program in eclipse, got an error "cannot find Opera binary".
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.opera.OperaDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class Opera
{
public static void main(String[] args)
{
WebDriverManager.operadriver().setup();
WebDriver d = new OperaDriver();
d.get("http://amazon.ae");
d.close();
}
}
How to solve this , please help..
Try to specify the path of your Opera launcher binary:
String operaBinary = "C:\\Program Files\\Opera\\launcher.exe"; // If Windows
WebDriverManager.operadriver().setup();
OperaOptions options = new OperaOptions();
options.setBinary(operaBinary);
WebDriver driver = new OperaDriver(options);
// ...
Related
Am trying to zoom out of my current page as some of the monitors are quite small there our application is not loading properly.
Selenium 3.141.59
Java 1.8
This is my sample code:
public class ScreenResolutionCheck {
static WebDriver driver = null;
public static void main(String[] args) {
int width = 1512, height = 982; //Default Macbook Pro Size
WebDriverManager webDriverManager = WebDriverManager.chromedriver().browserInDocker().enableVnc().linux().dockerScreenResolution(width + "x" + height +"x24").timeout(100);
driver = webDriverManager.create();
BaseFunctions.logInfoWithOutScreenShot("VNC Url",webDriverManager.getDockerNoVncUrl().toString());
driver.get("https://opensource-demo.orangehrmlive.com/");
driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.COMMAND, Keys.SUBTRACT));
findElement(By.id("txtUsername")).sendKeys("Admin");
findElement(By.id("txtPassword")).sendKeys("admin123");
findElement(By.id("btnLogin")).click();
findElement(By.id("menu_admin_viewAdminModule")).click();
findElement(By.id("tableWrapper"));
driver.quit();
webDriverManager.quit();
}
public static WebElement findElement(By by) {
WebElement we = new WebDriverWait(driver, 30).until(d -> d.findElement(by));
return we;
}
}
I tried the following:
driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.COMMAND,Keys.SUBTRACT));
driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.COMMAND,Keys.SHIFT,Keys.SUBTRACT));
driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.COMMAND,"-"));
new Actions(driver).sendKeys(driver.findElement(By.tagName("body"),Keys.chord(Keys.COMMAND,Keys.SUBTRACT)).build().perform();
js.executeScript("arguments[0].dispatchEvent(new KeyboardEvent('keydown',{'key':'Meta'}))",we);
js.executeScript("arguments[0].dispatchEvent(new KeyboardEvent('keydown',{'key':'+'}))",we);
js.executeScript("arguments[0].dispatchEvent(new KeyboardEvent('keyup',{'key':'Meta'}))",we);
js.executeScript("arguments[0].dispatchEvent(new KeyboardEvent('keyup',{'key':'+'}))",we);
options.addArguments("force-device-scale-factor=0.75");
options.addArguments("high-dpi-support=0.75");
WebDriver driver = new ChromeDriver(options);
Only this one worked but its not optimal as the moment I navigate to next screen, the zoom gets resetted.
js.executeScript("document.body.style.zoom='80%'");
I followed all these links but none worked for me. Any help would be much appreciated.
StackOverflowQuestion
Also Robot class doesn't suit me as I had to run in different OSes.
I'm getting an IllegalStateException thrown when running the following code:
package newprojectss;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Tours {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver","C:\\selenium-2.25.0\\chromedriver_win32");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://demo.guru99.com/test/newtours/";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Fire fox 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 with 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();
}
}
What can cause the problem?
illegalstateexception occurs because the chrome driver is not set properly
System.setProperty("webdriver.chrome.driver","C:\\selenium-2.25.0\\chromedriver_win32")
Chrome driver path doesn't point till chromedriver.exe file
Unzip your driver folder and point the location till chromedriver.exe
Eg: C://Users//username//Desktop//chromedriver.exe
I am struggling #AfterStep/#Beforestep in cucumber selenium java project.
when i used #AfterStep cucumber hook it not executes that method(it skips that method)
I tried with many versions but still not luck.
Can anyone help me with latest versions POM file which has no compatibility issue
I put this file at stepDefinition and using cucumber.api.java.AfterStep
#AfterStep
public void tearDown(Scenario scenario) throws IOException, JiraException
{
System.out.println("in step method");
if (scenario.isFailed()) {
System.out.println("in failes screen");
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String path=null;
path=System.getProperty("user.dir")+"\\target\\Screenshot\\"+System.currentTimeMillis()+".png";
FileUtils.copyFile(scrFile, new File(path));
Reporter.addScreenCaptureFromPath(path);
Reporter.addStepLog(scenario.getId());
}
}
TestRunner:
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/extentPackage/LoginToABSi.feature"},
glue = {"stepDefinitions"},
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:target/report.html"}
)
public class RunCukesTest {
public static WebDriver driver;
public static WebDriverWait wait;
public static ExtentProperties extentProperties;
#AfterClass
public static void teardown() {
Reporter.loadXMLConfig(new File("Report-Config/extent-config.xml"));
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Mac OSX");
Reporter.setTestRunnerOutput("Sample test runner output message");
}
Coud anybody help me fix my problem? When I tried to run jbpm sample in eclipse. This is code:
public class ProcessMain {
public static void main(String[] args) {
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieBase kbase = kContainer.getKieBase("kbase");
RuntimeManager manager = createRuntimeManager(kbase);
RuntimeEngine engine = manager.getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
ksession.startProcess("com.sample.bpmn.hello");
manager.disposeRuntimeEngine(engine);
System.exit(0);
}
private static RuntimeManager createRuntimeManager(KieBase kbase) {
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get()
.newDefaultBuilder().entityManagerFactory(emf)
.knowledgeBase(kbase);
return RuntimeManagerFactory.Factory.get()
.newSingletonRuntimeManager(builder.get(), "com.sample:example:1.0");
}
}
Then, this is error in console window:
Exception in thread "main" java.lang.IllegalArgumentException: Driver class name cannot be empty.
at org.kie.test.util.db.internal.DatabaseProvider.fromDriverClassName(DatabaseProvider.java:32)
at org.kie.test.util.db.DataSourceFactory.setupPoolingDataSource(DataSourceFactory.java:57)
at org.kie.test.util.db.DataSourceFactory.setupPoolingDataSource(DataSourceFactory.java:42)
at org.jbpm.test.JBPMHelper.setupDataSource(JBPMHelper.java:103)
at com.sample.ProcessMain.createRuntimeManager(ProcessMain.java:34)
at com.sample.ProcessMain.main(ProcessMain.java:23)
jBPMHelper no longer sets default values for H2,- https://github.com/kiegroup/drools/commit/34293e9675ae4f36f2a3a9e633305bbcc8260d19
We need to use - PersistenceUtil.setupPoolingDataSource(); instead JBPMHelper.setupDataSource();
Also include datasource.properties file at resources folder.
datasource.properties - > https://github.com/kiegroup/jbpm/blob/master/jbpm-examples/src/main/resources/datasource.properties
is there any ways to achieve type casting of local instance of WebDriver through ThreadLocal<WebDriver> to MarionetteDriver??? My code goes like this
public class Base_Class
{
protected ThreadLocal<WebDriver> Driver = null;
#BeforeMethod
#Parameters("BrowserName")
public void setUp(#Optional("Firefox") String BrowserName) throws MalformedURLException
{
Driver = new ThreadLocal<WebDriver>();
if(BrowserName.equalsIgnoreCase("FireFox"))
{
System.setProperty("webdriver.gecko.driver", "..//BrowserDrivers//wires");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
Driver = new <ThreadLocal<WebDriver>> MarionetteDriver(capabilities);
}
else if(BrowserName.equalsIgnoreCase("Chrome"))
{
System.setProperty("webdriver.chrome.driver", "..//BrowserDrivers//chromedriver");
Driver = new <ThreadLocal<WebDriver>>ChromeDriver();
}
}
public WebDriver getDriver()
{
return Driver.get();
}
#AfterMethod
public void closeBrowser()
{
getDriver().quit();
}
}
And all the test case are defined in separate classes which extends this above Base_Class.
Getting Error # Driver = new <ThreadLocal<WebDriver>> MarionetteDriver(capabilities); and Driver = new <ThreadLocal<WebDriver>>ChromeDriver(); lines as Type mismatch: cannot convert from MarionetteDriver to ThreadLocal<WebDriver>
I am using Chrome Version 52.0.2743.116 (64-bit) and FireFox Version 48.0 version browsers on Ubuntu 14.04 Os and Selenium version selenium-server-standalone-2.53.0
Wanted to achieve parallel test execution through testng.xml file..
any help would be highly appreciated..
You need to make the below changes in your code to make it compile.
Create MarionetteDriver object with your DesiredCapabilities and
Set this Driver object inside ThreadLocal object using its set method.
Like below :
if(BrowserName.equalsIgnoreCase("FireFox")) {
System.setProperty("webdriver.gecko.driver", "..//BrowserDrivers//wires");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
// Commented out below line from your code
//Driver = new <ThreadLocal<WebDriver>> MarionetteDriver(capabilities);
Driver.set(new MarionetteDriver(capabilities));
}
Try this and let me know