Code Snippet -
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SeleniumClientClass {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","D:\\YoutubeVideos\\Selenium\\geckodriver.exe");
/* DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setCapability("marionette", true); */
try {
FirefoxOptions opts = new FirefoxOptions().setLogLevel(FirefoxDriverLogLevel.TRACE);
WebDriver driver = new FirefoxDriver(opts);
driver.get("http://www.google.com");
Thread.sleep(10);
System.out.println("Application title is ============>>>>>>> "+driver.getTitle());
driver.quit();
} catch(Exception e) {
System.out.println(e);
}
}
}
Error I am getting:
org.openqa.selenium.WebDriverException:
java.net.ConnectException: Failed to connect to
localhost/127.0.0.1:38558 Build info: version: '3.12.0', revision:
'7c6e0b3', time: '2018-05-08T15:15:03.216Z' System info: host:
'MPL-CJ08HM2', ip: '192.168.56.1', os.name: 'Windows 10', os.arch:
'amd64', os.version: '10.0', java.version: '9.0.4' Driver info:
driver.version: FirefoxDriver
I got this issue resolved by having latest version of geckodriver.exe (v0.20.1) as I was earlier using older version of geckodriver(v0.9.0)...
Related
On doing a driver.close();driver.quit(); during the execution of java code, the following error is thrown:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Tried to run command without establishing a connection
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\admin\AppData\Local\Temp\rust_mozprofile.ENTBvl2aDbSs, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, moz:headless=false, platform=XP, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=56.0.2, platformVersion=10.0, moz:processID=5004, browserName=firefox, javascriptEnabled=true, platformName=XP}]
Session ID: 82e7dabd-c178-4d90-a3f8-84dc3f6ff14f
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:643)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:482)
at yahoo.main(yahoo.java:34)
Sharing code that throws the above exception :
//package basicSeleniumScripts;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class yahoo {
public static void main(String[] args) {
String Firefoxdriverpath = "C:\\Marionette\\geckodriver_1.exe";
WebDriver driver;
System.setProperty("webdriver.gecko.driver",Firefoxdriverpath);
//create a new instance of Firefox driver
driver = new FirefoxDriver();
//Open the page we want to open
driver.get("http://www.yahoo.com");
//Defining expected title
String expectedTitle = "Yahoo";
//Getting the actual title
String actualTitle = null;
actualTitle = driver.getTitle();
//Validating the TestCase
if (actualTitle.contentEquals(expectedTitle))
{
System.out.println("Test Passed");
}
else
{
System.out.println("Test Failed!!!");
}
driver.close();
driver.quit();
}
}
Update the gecko driver version to v0.19.0 as you are using 3.6.0 jars of selenium.
Also use quit method only
I have written a selenium test for yahoo website. In this test I am testing Yahoo News. But this code is throwing an Exception. So please solve the problem?
I am using Eclipse IDE, and Firefox as browser.
Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Tests {
WebDriver driver;
Wait<WebDriver> wait;
boolean result;
Tests() {
driver = new FirefoxDriver();
wait = new WebDriverWait(driver, 30);
driver.get("http://www.yahoo.com/");
}
public static void main(String arg[]) {
new Tests().news();
}
public boolean news() {
try {
System.out.print("Testing News... ");
driver.findElement(By.linkText("https://www.yahoo.com/news/")).click();
driver.findElement(By.partialLinkText("/news/world/")).click();
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
return webDriver.findElement(By.id("th-title")) != null;
}
});
return driver.findElement(By.id("th-title")).getText().contains("World");
}
catch(Exception exp) {
exp.printStackTrace();
return false;
}
}
}
Exception:
Testing News... org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"https://www.yahoo.com/news/"}
Command duration or timeout: 21.55 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'Jahanzeb', ip: '10.99.14.207', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
*** Element info: {Using=link text, value=https://www.yahoo.com/news/}
Session ID: 7576b452-dcb2-448f-844c-6c8b499561f1
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=46.0.1}]
FAILED
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:428)
at org.openqa.selenium.By$ByLinkText.findElement(By.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at Tests.news(Tests.java:72)
at Main.main(Main.java:14)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"https://www.yahoo.com/news/"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'Jahanzeb', ip: '10.99.14.207', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/JAHANZ~1/AppData/Local/Temp/anonymous2826618494991255784webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10770)
at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/JAHANZ~1/AppData/Local/Temp/anonymous2826618494991255784webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10779)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/JAHANZ~1/AppData/Local/Temp/anonymous2826618494991255784webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/JAHANZ~1/AppData/Local/Temp/anonymous2826618494991255784webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/JAHANZ~1/AppData/Local/Temp/anonymous2826618494991255784webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Please examine Yahoo page.
Please press Ctrl-F and try to find a text: "https://www.yahoo.com/news/">
There is no such a text there.
But if you look into a html source of this page, you will find this A tag with href attriibutte = ""https://www.yahoo.com/news/":
<a class="C(#fff) Td(n) Td(u):h" href="https://www.yahoo.com/news/"
data-reactid=".pgwo63s1xy.$tgtm-UH-0-Header.1.0.0:$news.0">News</a>
But a "link text" of this link is not "https://www.yahoo.com/news/", but "News" . The By#linkText method is looking for the link text (in this case "News"), not for href attributte.
You need to replace this command:
driver.findElement(By.linkText("https://www.yahoo.com/news/")).click();
with this one:
driver.findElement(By.linkText("News")).click();
package android.appium;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.annotations.AfterTest;
import io.appium.java_client.AppiumDriver;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SimpleTestCalc {
WebDriver driver;
#BeforeTest
public void setup () throws MalformedURLException {
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability("deviceName","ZX1PC2JJPM");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "5.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.calculator");
URL url1=new URL("http://127.0.0.1:4723/wd/hub");
driver=new RemoteWebDriver(url1,capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
#Test
public void sum() {
driver.findElement(By.name("2")).click();
driver.findElement(By.name("5")).click();
driver.findElement(By.name("+")).click();
driver.findElement(By.name("5")).click();
driver.findElement(By.name("=")).click();
String result=driver.findElement(By.className("android.widget.EditText")).getText();
System.out.print("Sum of values is"+result);
}
#AfterTest
public void reset() {
driver.quit();
}
}
Output:
[TestNG] Running:
C:\Users\vgaarlap.ORADEV\AppData\Local\Temp\testng-eclipse--1070157593\testng-customsuite.xml
FAILED CONFIGURATION: #BeforeTest setup
org.openqa.selenium.SessionNotCreatedException: A new session could
not be created. (Original error: 'java -version' failed. Error: spawn
ENOENT) (WARNING: The server did not provide any stacktrace
information) Command duration or timeout: 149 milliseconds Build info:
version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'VGAARLAP-LAP', ip: '192.168.56.1', os.name:
'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version:
'1.8.0_31' Driver info: org.openqa.selenium.remote.RemoteWebDriver at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
You need to add system32 location in your environment path variable.
%SystemRoot%system32
For further details see the below link:
https://discuss.appium.io/t/original-error-java-version-failed-error-spawn-enoent/3125
I am using Selenium Web Driver and Java in the Eclipse and I am trying to read xpath/Class id / link id from "Object.Properties" file stored in the src folder under package folder and populate test data from database. However, after reading 2nd property from following property file script is not reading property for Email, Pwd and Submit. I am not able to figure it out why script is not reading these property.
My Script will identify web field, button, link using xpath / Class id / link id from "Object.Properties" file stored in the src folder under package folder. And for web page field script will bring test data from database and populate them in the particular field on the web page.
Following property are stored in the "Object.Properties" file and this property file is stored in the src folder under package folder:
URL = http://web.com/user-portal
ClickOnLoginLink = //*[#id='app']/div/main/section/ul/li[1]/a
Email = //input[#name='username']
Pwd = //input[#name='password']
Submit = //button[#name='loginButton']
Following Failure exception display:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//input[#name='username']"}
Command duration or timeout: 12 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'CAEITVDI-085', ip: '172.23.212.109', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_66'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=41.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: d0672bd2-d9d0-413e-a734-1865a9cce733
*** Element info: {Using=xpath, value=//input[#name='username']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at com.provider.ProApp.testUserNamePassword(ProApp.java:76)
at com.provider.ProApp.setUpConnection(ProApp.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//input[#name='username']"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'CAEITVDI-085', ip: '172.23.212.109', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_66'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/SAV19734/AppData/Local/Temp/anonymous6689352326673970234webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10723)
at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/SAV19734/AppData/Local/Temp/anonymous6689352326673970234webdriver-profile/extensions/fxdriver#googlecode.com/components/driver-component.js:10732)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/SAV19734/AppData/Local/Temp/anonymous6689352326673970234webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12614)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/SAV19734/AppData/Local/Temp/anonymous6689352326673970234webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12619)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/SAV19734/AppData/Local/Temp/anonymous6689352326673970234webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:12561)
Here is my Base class Code:
package com.provider;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;
import oracle.net.ns.NetException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeSuite;
public class BaseClass {
static WebDriver driver;
#BeforeSuite
public void setup() throws InterruptedException, IOException{
driver=new FirefoxDriver();
driver.manage().window().maximize();
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") +"\\src\\com\\provider\\Object.Properties");
obj.load(objfile);
driver.get(obj.getProperty("URL"));
}
}
Here is my Extended class Code:
package com.provider;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;
public class ProApp extends BaseClass{
#Test
public void setUpConnection() throws ClassNotFoundException, SQLException, FileNotFoundException, InterruptedException, IOException {
String driver_DBPath = "jdbc:oracle:thin:#Host:Port:SID";
String DB_username = "*****";
String DB_password = "*****";
String Query = "select * from Table";
Connection con = DriverManager.getConnection(driver_DBPath, DB_username, DB_password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(Query);
while(rs.next()){
String Email = rs.getString("CLAIM_NUMBER");
String Pwd = rs.getString("INDIVIDUAL_NUM");
testUserNamePassword(Email, Pwd);
}
}
#Test(priority=1)
public void clickLoginLink() throws InterruptedException, IOException {
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") +"\\src\\com\\provider\\Object.Properties");
obj.load(objfile);
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("ClickOnLoginLink"))).click();
Thread.sleep(1000);
}
#Test(priority=2)
public void testUserNamePassword(String Email1, String Pwd1) throws InterruptedException, IOException {
Thread.sleep(1000);
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") +"\\src\\com\\provider\\Object.Properties");
obj.load(objfile);
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Email"))).clear();
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Email"))).sendKeys(Email1);
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Pwd"))).clear();
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Pwd"))).sendKeys(Pwd1);
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Submit"))).click();
Thread.sleep(1000);
}
#Test(priority=3)
public void loginVerify() throws InterruptedException, IOException{
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") +"\\src\\com\\provider\\Object.Properties");
obj.load(objfile);
Assert.assertEquals("Wel Come To Testing World!!!", driver.findElement(By.xpath(obj.getProperty("WelComeToTestingWorld"))).getText());
}
#Test(priority=4)
public void logonVerify() throws InterruptedException, IOException{
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") +"\\src\\com\\provider\\Object.Properties");
obj.load(objfile);
WebElement DashboardHeader = driver.findElement(By.xpath(obj.getProperty("WelComeToTestingWorld")));
DashboardHeader.getText().equals("Wel Come To Testing World!!!");
}
}
Actually, I figure it out that I haven't given Priority where I have provided database connection method information so that when script is running then script is following TestNG framework in order to execute test and script start executing Test(priority=1), Test(priority=2) and so on... And for database connection where I only provided "Test" before starting database connection method. I should have also prioritize database connection method as Test(priority=2). So just prioritize database connection method resolve my issue.
I was trying to open selenium.org and click on project tab but the object was not identifiable(even using uiautomator until the page was zoomed).Hence also trying to zoom so that object is identifiable. But zoom is not functioning.Is there some other way that i can find the element.
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.io.File;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.FindBy;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class OpenBrowser {
private AppiumDriver <WebElement> AndDriver;
#BeforeMethod
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("device", "Android");
capabilities.setCapability("deviceName", "TA9330416L");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.chrome");
capabilities.setCapability("appActivity", "org.chromium.chrome.browser.document.ChromeLauncherActivity");
AndDriver = new AndroidDriver <WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}
#AfterMethod
public void tearDown() throws Exception {
AndDriver.quit();//Always quit your driver
}
#Test
public void launchWebsite()throws InterruptedException {
AndDriver.get("http://www.seleniumhq.org");
Thread.sleep(3000);
AndDriver.pinch(323,323);
AndDriver.findElement(By.name("Projects")).click();
}
}
/*
FAILED: launchWebsite
org.openqa.selenium.WebDriverException: unknown error: operation is unsupported on Android
(Session info: chrome=46.0.2490.76)
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 18 milliseconds
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'USHYDPTHAKURI1', ip: '10.14.225.155', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_40'
Driver info: io.appium.java_client.android.AndroidDriver
*/
With capabilities you provided you will get Chromium as application, not browser. So, there is no method 'get' for this application.