FAILED CONFIGURATION: #BeforeMethod setUp - Selenium Java TestNG - java

I am trying to execute Selenium Java Project with TestNG but I am getting the Configurations Problems related to TestNG annotations. I am using Page object model design pattern. The chromedriver gets executed successfully for each testcase and it lands on login page but after that it crashes and gives error about Failed Configurations #BeforeMethod.
I am sharing the whole code and console errors. Any Solution for this folks! Been stuck here for the long time.
Page Classes.
Base Page:
package Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
public class BasePage{
public WebDriver driver;
public WebDriverWait wait;
public BasePage(WebDriver driver, WebDriverWait wait) {
this.driver = driver;
this.wait = wait;
}
//Generic Methods
public void click(By elementlocation) {
driver.findElement(elementlocation).click();
}
public void writeText(By elementlocation, String text) {
driver.findElement(elementlocation).sendKeys(text);
}
public String readText(By elementlocation) {
return driver.findElement(elementlocation).getText();
}
public void waitVisibility(By elementlocation) {
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(elementlocation));
}
public void waitElementToBeClickable(By elementlocation ) {
wait.until(ExpectedConditions.elementToBeClickable(elementlocation));
}
public void assertEquals (By elementlocation, String expectedText) {
waitVisibility(elementlocation);
Assert.assertEquals(readText(elementlocation), expectedText);
}
}
Login Page with Methods:
package Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage extends BasePage{
public LoginPage(WebDriver driver, WebDriverWait wait) {
super(driver, wait);
}
By email = By.xpath("//input[#data-placeholder='Enter your username']");
By pwd = By.xpath("//input[#data-placeholder='Enter your Password']");
By LoginBtn = By.xpath("//button//span[text()='Login']");
By emptyLoginVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
By emptyPasswordVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
By emptyUserNameVerification = By.xpath("//span[contains(text(),'Both Password and user name are required.')]");
//methods
public LoginPage LoginToAMS(String username, String password) {
writeText(email, username);
writeText(pwd, password);
click(LoginBtn);
return this;
}
public LoginPage EmptyLoginVerification (String expectedText) {
assertEquals(emptyLoginVerification, expectedText);
return this;
}
public LoginPage EmptyPasswordVerification (String expectedText) {
assertEquals(emptyPasswordVerification, expectedText);
return this;
}
public LoginPage EmptyUserNameVerification (String expectedText) {
assertEquals(emptyUserNameVerification, expectedText);
return this;
}
}
Below are the TestClasses Now.
BaseTest:
package tests;
import java.time.Duration;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
public class BaseTest {
public WebDriver driver;
public WebDriverWait wait;
#BeforeMethod
public void setup() {
System.setProperty("WebDriver.chrome.driver", "C:\\eclipse\\eclipse-workspace\\ams\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver, Duration.ofSeconds(15));
driver.manage().window().maximize();
driver.get("http://dummyweb.com");
}
#AfterMethod
public void teardown() {
driver.close();
}
}
And here is the actual TestClass:
package tests;
import static org.testng.Assert.assertEquals;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import Pages.HomePage_ListOfItems;
import Pages.LoginPage;
public class LoginTestCases extends BaseTest{
LoginPage loginpage = new LoginPage(driver, wait);
private String username = "nasir.n#planet.com";
private String password = "123456";
#Test(priority=0)
public void Valid_Login_To_AMS() {
loginpage.LoginToAMS(username, password);
}
#Test(priority=1)
public void Empty_Login_To_AMS() {
loginpage.LoginToAMS("","");
loginpage.EmptyLoginVerification("Both Password and user name are required.");
}
#Test(priority=2)
public void UserName_EmptyPassword() {
loginpage.LoginToAMS(username,"");
loginpage.EmptyPasswordVerification("Both Password and user name are required.");
}
#Test(priority=4)
public void EmptyUserName_PasswordFill( ) {
loginpage.LoginToAMS("", password);
loginpage.EmptyUserNameVerification("Both Password and user name are required.");
}
}
The errors that I am getting are below:
[RemoteTestNG] detected TestNG version 7.4.0
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951#{#904}) on port 52405
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
May 30, 2022 8:45:44 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
May 30, 2022 8:45:44 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 101, so returning the closest version found: a no-op implementation
May 30, 2022 8:45:44 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 101.
May 30, 2022 8:45:44 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.1` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951#{#904}) on port 50748
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
May 30, 2022 8:46:30 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
May 30, 2022 8:46:31 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 101, so returning the closest version found: a no-op implementation
May 30, 2022 8:46:31 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 101.
May 30, 2022 8:46:31 PM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.1` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.
FAILED CONFIGURATION: #BeforeMethod setup
org.openqa.selenium.WebDriverException: unknown error: cannot determine loading status
from disconnected: unable to send message to renderer
(Session info: chrome=101.0.4951.67)
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'NASIR-S-LTP', ip: '192.168.10.18', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [afb96e2642d9f544c41d7d722caab5d3, get {url=http://dev-ims.dplit.com/}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 101.0.4951.67, chrome: {chromedriverVersion: 101.0.4951.41 (93c720db8323..., userDataDir: C:\Users\nasir.n\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:53544}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:53544/devtoo..., se:cdpVersion: 101.0.4951.67, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: afb96e2642d9f544c41d7d722caab5d3
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:312)
at tests.BaseTest.setup(BaseTest.java:29)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>amsdev</groupId>
<artifactId>ams</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

When I copy paste your code, I see the system property is set wrong. The correct one should be
System.setProperty("webdriver.chrome.driver", "C:\\UserTemp\\tools\\chrome\\chromedriver.exe");
Notice the small cases here.
Second thing I did was to Initialize the LoginPage In every test method. Else it become null and throws null pointer exception.
#Test(priority = 4)
public void EmptyUserName_PasswordFill() {
LoginPage loginpage = new LoginPage(driver, wait);
loginpage.LoginToAMS("", password);
loginpage.EmptyUserNameVerification("Both Password and user name are required.");
}
I did not had chrome so downloaded the latest version
and corresponding driver.
ChromeDriver 102.0.5005.61
For me all the 3 test cases passes, except the first one where the authentication is not successful.
Please note that I had edge browser and with correct driver, the test passes in edge as well.
The loginPage instance to be created in all the test methods is the change I did to solve the null pointer exception.

Some addition answering "why LoginPage instance needs to be created in all test methods?". You should initialize your page object after your driver has been initialized.
In your example TestNg creates an instance of your test class where the field
LoginPage loginpage = new LoginPage(driver, wait);
is initialized right away. By that moment your set up method has not yet been executed hence you pass null as driver to your page object.

Related

Why doesn't Selenium #FindBy work with name, xpath, css

I have a Java program using Selenium and would like to use #FindBy(), but I can't solve the problem. My program is composed of several lines. I would like to share tasks between classes. And for that, I started with identity verification. I created this class which includes login and password.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
public class LoginPageNew {
WebDriver webDriver;
public LoginPageNew(WebDriver driver) {
this.webDriver = driver;
}
#FindBy(css = "[name='username']")
#CacheLookup
WebElement username;
#FindBy(how = How.NAME, using = "password")
#CacheLookup
WebElement password;
#FindBy(how = How.XPATH, using = "//button[normalize-space()='Login']")
#CacheLookup
WebElement submit_btn;
public void loginPage() {
username.sendKeys("Admin");
password.sendKeys("admin123");
submit_btn.click();
}
}
And I created this class
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class BrowserFactory {
static WebDriver driver;
public static WebDriver startBrowser(String browserName, String url) {
if (browserName.equals("chrome")) {
driver = new ChromeDriver();
}
driver.manage().window().maximize();
driver.get(url);
return driver;
}
}
And finally this test class
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;
public class VerifyLoginPage {
#Test
public void checkValidUser() {
WebDriver webDriver = BrowserFactory.startBrowser("chrome", "http://opensource-demo.orangehrmlive.com/");
LoginPageNew pageNew = PageFactory.initElements(webDriver, LoginPageNew.class);
pageNew.loginPage();
}
}
For me, I would like to work with the site "https://opensource-demo.orangehrmlive.com/" with login and password "Admin" and "admin123" with this architecture to do the test.
And I used
#FindBy(name="username"), #FindBy(css = "[name='username']"),
#Find By(xpath = "//input[#placeholder='Username']")
#Find By(xpath = "(//input[#placeholder='Username'])[1]")
#Find By(how = How. NAME, using = "username")...
But there is no solution, always the same error.
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[name='username']"}
(Session info: chrome=109.0.5414.76)
For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element
Build info: version: '4.7.2', revision: '4d4020c3b7'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.16'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [f3cd14b65540143dd77567fdbdd70945, findElement {using=css selector, value=
[name='username']}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 109.0.5414.76,
chrome: {chromedriverVersion: 109.0.5414.74 (e7c5703604da..., userDataDir:
C:\Users\hp\AppData\Local\T...}, goog:chromeOptions: {debuggerAddress: localhost:64620},
networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy:
Proxy(), se:cdp: ws://localhost:64620/devtoo..., se:cdpVersion: 109.0.5414.76, setWindowRect:
true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script:
30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true,
webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
I will add this code
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
thank you BMW83

Using Relative Locators results in org.openqa.selenium.NoSuchElementException: Cannot locate an element using [unknown locator] with Selenium Java

I'm using selenium 4 and trying to locate some elements (Username and password credentials) "Username : Admin
Password : admin123" using Relative Locators selenium 4 new feature but the Code throws org.openqa.selenium.NoSuchElementException: Cannot locate an element using [unknown locator] but when I debugged the code to test it, it passed successfully ,found the elements and printed the values on the console. anyone has a proposed solution?
org.openqa.selenium.NoSuchElementException: Cannot locate an element using \[unknown locator\]
For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element
Build info: version: '4.4.0', revision: 'e5c75ed026a'
System info: host: 'DESKTOP-M0R33E6', ip: '192.168.1.4', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.2'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.By.findElement(By.java:124)
at org.openqa.selenium.remote.ElementLocation$ElementFinder$1.findElement(ElementLocation.java:136)
at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:80)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:365)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:357)
at OrangeHrm.Pages.LoginPage.getUsernameUsingRelativeLocator(LoginPage.java:29)
at OrangeHrm_Tests.Login.LoginTests.test_GetUserCredentials(LoginTests.java:10)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:673)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:220)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:945)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:193)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
at org.testng.TestRunner.privateRun(TestRunner.java:808)
at org.testng.TestRunner.run(TestRunner.java:603)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
at org.testng.SuiteRunner.run(SuiteRunner.java:326)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.runSuites(TestNG.java:1092)
at org.testng.TestNG.run(TestNG.java:1060)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Website URL: https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
LoginPage.java
package OrangeHrm.Pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.locators.RelativeLocator;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage {
private WebDriver driver;
private By loginPageTitle = By.tagName("h5");
WebElement usernameCredential;
WebElement passwordCredential;
public LoginPage(WebDriver driver){
this.driver = driver;
}
public String getUsernameUsingRelativeLocator(){
usernameCredential = driver.findElement(RelativeLocator.with(By.xpath("//div[contains(#class , 'oxd-sheet--rounded')]/p[1]"))
.below(loginPageTitle));
System.out.println(usernameCredential.getText());
return usernameCredential.getText();
}
public String getPasswordUsingRelativeLocator(){
passwordCredential = driver.findElement(RelativeLocator.with(By.xpath("//div[contains(#class , 'oxd-sheet--rounded')]/p[2]"))
.below(username));
System.out.println(passwordCredential.getText());
return passwordCredential.getText();
}
}
OrangeHrmWebTestBase.java
package OrangeHrm_Tests.Base;
import OrangeHrm.Pages.LoginPage;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.time.Duration;
public class OrangeHrmWebTestBase {
private WebDriver driver;
protected LoginPage loginPageObj;
#BeforeClass
public void setUp(){
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://opensource-demo.orangehrmlive.com/");
loginPageObj = new LoginPage(driver);
}
#AfterClass
public void teatDown(){
driver.quit();
}
}
LoginTests.java
package OrangeHrm_Tests.Login;
import OrangeHrm_Tests.Base.OrangeHrmWebTestBase;
import org.testng.annotations.Test;
public class LoginTests extends OrangeHrmWebTestBase {
#Test
public void test_GetUserCredentials(){
loginPageObj.getUsernameUsingRelativeLocator();
loginPageObj.getPasswordUsingRelativeLocator();
}
}
You seem to be pretty close using Below as a Relative Locator within the OrangeHRM website.
However instead of using the <div> with the text Username : Admin and Password : admin123 as Relative Locators you can use the <label> with text as Username and Password.
Code Block:
package AwesomeDay;
import java.time.Duration;
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.support.locators.RelativeLocator;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class RelativeLocators2 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");
//WebElement userNameLabel = driver.findElement(By.xpath("//label[text()='Username']"));
WebElement userNameLabel = new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[text()='Username']")));
By userName = RelativeLocator.with(By.tagName("input")).below(userNameLabel);
driver.findElement(userName).sendKeys("Ali");
WebElement passwordLabel = driver.findElement(By.xpath("//label[text()='Password']"));
By password = RelativeLocator.with(By.tagName("input")).below(passwordLabel);
driver.findElement(password).sendKeys("Eleish");
}
}
Browser Snapshot:

I m able to open and automate other apk with appium, but not able to op "Vlearning" apk with Appium script. getting error "SessionNotCretedException"

This is my base class which is used to start Appium server
package VLearning.VLearningAppium;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import com.google.common.collect.ImmutableMap;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
public class VlearningBaseClass {
public AndroidDriver driver;
public AppiumDriverLocalService service;
#BeforeClass
public void appiumConfigure() throws MalformedURLException
{
//Code to start Appium server instead of starting Appium server manually in CMD.
//Here main.js responsible for start Appium server, so we provided location of main.js
service = new AppiumServiceBuilder().withAppiumJS(new File("C:\\Users\\USER\\"
+ "AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js")).withIPAddress("127.0.0.1").usingPort(4723).build();
service.start();
//UiAutomator2Options which is used to set device name,application location etc.
UiAutomator2Options options = new UiAutomator2Options();
//options.setDeviceName("Nexus_One_Appium"); //device name, for virtual devices
options.setDeviceName("Android Device"); //for real devices
//set Chrome driver location for Selenium automation for hybrid application
//options.setChromedriverExecutable("C:\\Users\\USER\\eclipse-workspace\\VLearningAppium\\src\\test\\java\\resources\\chromedriver.exe");
//application location
//Vlearning apk
options.setApp("C:\\Users\\USER\\eclipse-workspace\\VLearningAppium\\src\\test\\java\\resources\\app-debug.apk");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), options);
//with the help of "Appium inspector" we can identify the element in App. For that we need to download and install that
//we have to give information to "Appium inspector" in which device,in which App we have to inspect
//so in "Appium inspector" we need to give information like app, deviceName, platformName, automationName
//implicit wait
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
}
public void longPressActio(WebElement ele)
{
((JavascriptExecutor)driver).executeScript("mobile: longClickGesture",
ImmutableMap.of("elementId",((RemoteWebElement)ele).getId(),"duration",2000));
}
public void scrollingTillEnd()
{
//scrolling till last
boolean canScrollMore;
do
{
canScrollMore = (Boolean)((JavascriptExecutor) driver).executeScript("mobile: scrollGesture", ImmutableMap.of(
"left",100,"top",100,"width",200,"height",200,"direction","down","percent",3.0));
}while(canScrollMore);
}
public void swipeAction(WebElement ele,String direction)
{
((JavascriptExecutor) driver).executeScript("mobile: swipeGesture",ImmutableMap.of(
"elementId",((RemoteWebElement)ele).getId(),
"direction",direction,
"percent",0.75
));
}
public void dragAndDropAction(WebElement ele)
{
((JavascriptExecutor) driver).executeScript("mobile: dragGesture", ImmutableMap.of(
"elementId",((RemoteWebElement) ele).getId(),
"endX",355,
"endY",316));
}
public double getFormatedAmount(String amount)
{
double price = Double.parseDouble(amount.substring(1));
return price;
}
#AfterClass
public void tearDown()
{
driver.quit();
service.stop();
}
}
'''
This is test cases inheriting above base class
package VLearning.VLearningAppium;
import org.openqa.selenium.By;
import org.testng.annotations.Test;
public class VlearningLogin extends VlearningBaseClass{
#Test
public void login()
{
driver.findElement(By.xpath("//android.widget.Button[#text='NEXT']")).click(); //Next button
driver.findElement(By.xpath("//android.widget.Button[#text='Get Started']")).click(); //Get Started Button
}
}
'''
I m getting error like this
[RemoteTestNG] detected TestNG version 7.6.1
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[35m[Appium][39m Welcome to Appium v2.0.0-beta.42
[35m[Appium][39m Non-default server args:
[35m[Appium][39m { address: [32m'127.0.0.1'[39m }
[35m[Appium][39m Attempting to load driver uiautomator2...
[debug] [35m[Appium][39m Requiring driver at C:\Users\USER\.appium\node_modules\appium-uiautomator2-driver
[35m[Appium][39m Appium REST http interface listener started on 127.0.0.1:4723
[35m[Appium][39m Available drivers:
[35m[Appium][39m - uiautomator2#2.4.6 (automationName 'UiAutomator2')
[35m[Appium][39m No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
FAILED CONFIGURATION: #BeforeClass VLearning.VLearningAppium.VlearningBaseClass.appiumConfigure
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.vista.vlearning' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: 'com.vista.vlearning.SplashActivity' or 'com.vista.vlearning.com.vista.vlearning.SplashActivity' never started. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting
Build info: version: '4.4.0', revision: 'e5c75ed026a'
System info: host: 'DESKTOP-K1E715A', ip: '192.168.1.113', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.16.1'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, newSession {capabilities=[{appium:deviceName=Android Device, platformName=ANDROID, appium:automationName=UIAutomator2, appium:app=C:\Users\USER\eclipse-workspace\VLearningAppium\src\test\java\resources\app-debug.apk}], desiredCapabilities=Capabilities {appium:app: C:\Users\USER\eclipse-works..., appium:automationName: UIAutomator2, appium:deviceName: Android Device, platformName: ANDROID}}]
Capabilities {}
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:126)
at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:146)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:224)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:79)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:87)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:116)
at VLearning.VLearningAppium.VlearningBaseClass.appiumConfigure(VlearningBaseClass.java:59)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
at org.testng.internal.invokers.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:180)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:122)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:806)
at org.testng.TestRunner.run(TestRunner.java:601)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:433)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:427)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:387)
at org.testng.SuiteRunner.run(SuiteRunner.java:330)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
at org.testng.TestNG.runSuites(TestNG.java:1099)
at org.testng.TestNG.run(TestNG.java:1067)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
'''
But when I place other apk location in
options.setApp("");
I am able to open and automate with appium..
but I am getting error when I place "Vlearning" apk in
options.setApp("");
when I posted this error in Udemy one instructor told me ist apk permission issue..if its Vlearning apk permission issue then how to resolve it?

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: androidx.test.uiautomator.StaleObjectException

I was trying to run this on the Android TV i see the Appium is able to click on all the buttons and input the data in text box except the very first one. i have to click on it then wait and used send keys to see if it solves the issue but no luck. can someone help me on this.enter image description here
Base.Java
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class Base {
public static AndroidDriver<AndroidElement> capabalities() throws MalformedURLException {
File file = new File ("src");
File fs = new File(file,"TVTestApp_ct.apk");
DesiredCapabilities capabalities = new DesiredCapabilities();
capabalities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
capabalities.setCapability(MobileCapabilityType.DEVICE_NAME, "Automation");
capabalities.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabalities);
return driver;
}
}
HomeScreen.Java
import java.net.MalformedURLException;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.StaleElementReferenceException;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
public class HomeScreen extends Base {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
AndroidDriver<AndroidElement> driver = capabalities();
driver.findElementById("com.tvexample.tvtestapp:id/editText").sendKeys("1234");
driver.findElementById("com.tvexample.tvtestapp:id/editText1").sendKeys("1234")
}
}
Logs:
Jun 21, 2021 2:11:47 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: androidx.test.uiautomator.StaleObjectException
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'TXCDTL20CT1696', ip: '135.70.71.74', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: C:\Users\cg517n\Documents\e..., appPackage: com.tvexample.tvtestapp, automationName: uiautomator2, databaseEnabled: false, desired: {app: C:\Users\cg517n\Documents\e..., automationName: uiautomator2, deviceName: Automation, platformName: android}, deviceApiLevel: 28, deviceManufacturer: unknown, deviceModel: sdk_google_atv_x86, deviceName: emulator-5554, deviceScreenDensity: 320, deviceScreenSize: 1920x1080, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, pixelRatio: 2, platform: LINUX, platformName: Android, platformVersion: 9, statBarHeight: 0, takesScreenshot: true, viewportRect: {height: 1080, left: 0, top: 0, width: 1920}, warnings: {}, webStorageEnabled: false}
Session ID: 75f6f7db-21e8-407e-8a53-59271e4e9e02
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
at HomeScreen.main(HomeScreen.java:18)

org.openqa.selenium.WebDriverException: chrome not reachable using Selenium and ChromeDriver

I created a test class using TestNG and in this class I defined 5 test methods. When I run the test, the TestNG console shows that 3 scenarios of the total of 5 have been executed (see the image below).
The registroNovo and tabulacaoTratamento methods are not executed.
When I close the browser (Chrome) the TestNG console displays the following error screen that follows below.
Eclipse console displays the following error message:
org.openqa.selenium.WebDriverException: chrome not reachable
(Session info: chrome=67.0.3396.87)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:36:59.109Z'
System info: host: 'RJO-BCC-C2A-H21', ip: '10.5.79.38', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.40.565498 (ea082db3280dd6..., userDataDir: C:\Users\lsnpere\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 67.0.3396.87, webStorageEnabled: true}
Session ID: 32d0291ab5ecaa1141f9997771edcd95
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
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:601)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.alert(RemoteWebDriver.java:987)
at org.openqa.selenium.support.ui.ExpectedConditions$28.apply(ExpectedConditions.java:808)
at org.openqa.selenium.support.ui.ExpectedConditions$28.apply(ExpectedConditions.java:804)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at page.RegistroNovo.registroNovo(RegistroNovo.java:25)
at test.ValidarFaturamentoRoamingTest.registroNovo(ValidarFaturamentoRoamingTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
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.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Has anyone ever seen this kind of error?
Basically I created 4 classes:
The BaseTest class which has all methods that are common to all test classes:
public class BaseTest {
public static WebDriver driver;
public static WebDriverWait wait;
#BeforeClass
public static void setup() {
System.setProperty("webdriver.chrome.driver", "e:\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver, 15);
driver.manage().window().maximize();
}
#AfterClass
public static void tearDown() throws InterruptedException {
Thread.sleep(5000);
driver.findElement(By.id("mn_sair"));
driver.quit();
}}
The test class ValidarFaturamentoRoamingTest which extends the class BaseTest:
public class ValidarFaturamentoRoamingTest extends BaseTest {
#Test(priority=0)
public void acessarBkoMais() {
HomePage homepage = new HomePage(driver, wait);
homepage.abrirBkoMais();
}
#Test(priority=1)
public void logarBkoMais() {
LoginPage logar = new LoginPage(driver, wait);
logar.loginBkoMais("000000", "000000");
}
#Test(priority=2)
public void logarEstrategia() {
LogarEstrategiaPage logarEstrategia = new LogarEstrategiaPage(driver, wait);
logarEstrategia.logarEstrategia();
}
#Test(priority=3)
public void registroNovo() {
RegistroNovo registroNovo = new RegistroNovo(driver, wait);
registroNovo.registroNovo();
}
#Test(priority=4)
public void tabulacaoTratamento() {
TratOsFatRoamPage rt = new TratOsFatRoamPage(driver, wait);
rt.TratOsFatRoam();
}}
The class TratOsFatRoamPage which extends the class BasePage.
public class TratOsFatRoamPage extends BasePage {
public TratOsFatRoamPage(WebDriver driver, WebDriverWait wait) {
super(driver, wait);
}
String idMotivo = "cboMotivo";
String idSubMotivo = "cboSubMotivo";
String idStatus = "cboStatus";
String qtdNumerosFaturas = "txtQtdFaturas";
String qtdNumerosCotas = "txtQtdContas";
String idObservacao = "txtObservacao";
String idSalvar = "btnSalvar";
public void TratOsFatRoam() {
writeText(By.id(qtdNumerosFaturas),"Teste 2018");
writeText(By.id(qtdNumerosCotas), "2018-2");
}}
And the class BasePage which has all the methods that are common classes:
public class BasePage {
public WebDriver driver;
public WebDriverWait wait;
public BasePage(WebDriver driver, WebDriverWait wait) {
this.driver = driver;
this.wait = wait;
}
public void click(By elementLocation) {
driver.findElement(elementLocation).click();
}
public void writeText(By elementLocation, String text) {
driver.findElement(elementLocation).sendKeys(text);
}
public String readText(By elementLocation) {
return driver.findElement(elementLocation).getText();
}
public void selectText(By elementLocation, String value) {
Select atividade = new Select(driver.findElement(elementLocation));
atividade.selectByValue(value);
}}
This error message...
org.openqa.selenium.WebDriverException: chrome not reachable
...implies that the ChromeDriver was unable to communicate with the WebBrowser i.e. Chrome Browsing session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.40
You are using chrome=67.0
Your Selenium Client version is 3.8.0 of 2017-11-30T11:36:59.109Z which is almost six months older.
Your JDK version is 1.8.0_131 which is pretty ancient.
So there is a clear mismatch between the JDK v8u131 , Selenium Client v3.8.0 , ChromeDriver v2.40 and Chrome Browser v67.0
org.openqa.selenium.WebDriverException: chrome not reachable
This means that for some reason there is no communication happening between driver and chrome instance; in your case that reason is you are closing it manually after 3 Tests are run.
and your TestNG console displays the error screen because last 2 test cases weren't run due to closing of browser.
So here your real issue is what is taking second last test to take time?
For that post some code.

Categories