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
Related
I have written a scrapper using selenium which uses chrome driver. It works well but some time it fails to quit chrome driver with following exception
org.openqa.selenium.WebDriverException: Timed out waiting for driver server to stop.
Build info: version: '4.1.3', revision: '7b1ebf28ef'
System info: host: '45-79-216-229.ip.linodeusercontent.com', ip: '45.79.216.229', os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.0-348.12.2.el8_5.x86_64', java.version: '11.0.14'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [66aa12cc87af0a6cf095436a6bbece90, quit {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 102.0.5005.61, chrome: {chromedriverVersion: 102.0.5005.61 (0e59bcc00cc4..., userDataDir: /tmp/.com.google.Chrome.DhJaWB}, goog:chromeOptions: {debuggerAddress: localhost:45009}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), se:cdp: ws://localhost:45009/devtoo..., se:cdpVersion: 102.0.5005.61, 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: 66aa12cc87af0a6cf095436a6bbece90
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:132)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:567)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:622)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:626)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:463)
at org.openqa.selenium.chromium.ChromiumDriver.quit(ChromiumDriver.java:293)
Code
I am adding my code here.
public class SeleniumScraper {
private WebDriver driver;
public SeleniumScraper() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = this.getDefaultChromeOptions();
this.driver = new ChromeDriver(options);
driver.manage().window().maximize();
}
public WebDriver getPage(String url) {
this.driver.get(url);
return driver;
}
public boolean quitDriver() {
this.driver.quit();
return true;
}
protected ChromeOptions getDefaultChromeOptions() {
HashMap<String, Object> chromePrefs = new HashMap<>(2);
chromePrefs.put("profile.default_content_settings.popups", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.setHeadless(true);
return options;
}
}
I tried
driver.close();
driver.quit();
it does not throw any exception now.
For now, using the latest serenity version (2.0.2) through maven I was able to simply perform an upload action like this:
import net.serenitybdd.core.annotations.findby.By;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Upload;
import net.serenitybdd.screenplay.targets.Target;
import net.serenitybdd.screenplay.waits.WaitUntil;
import java.nio.file.Path;
import java.nio.file.Paths;
import static net.serenitybdd.screenplay.Tasks.instrumented;
import static net.serenitybdd.screenplay.matchers.WebElementStateMatchers.isVisible;
public class PerformTheUpload implements Task {
public static Target UPLOAD_SOURCE_FILES_TARGET =
Target.the("Upload source files").located(By.id("uploadSourceFiles"));
public static final String TEST_FILE = "src/main/resources/files/test.txt";
public static final Path TEST_FILE_PATH = Paths.get(TEST_FILE).toAbsolutePath();
public static PerformTheUpload onTheField() {
return instrumented(PerformTheUpload.class);
}
#Override public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(WaitUntil.the(UPLOAD_SOURCE_FILES_TARGET, isVisible()));
actor.attemptsTo(Upload.theFile(TEST_FILE_PATH).to(UPLOAD_SOURCE_FILES_TARGET));
}
}
The problem with it is that it generates the following error:
org.openqa.selenium.UnsupportedCommandException: POST /session/76ec390f-dbbe-48c2-be32-931969d81210/file did not match a known command
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'TAG-614', ip: '10.10.37.89', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 62.0.3, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.22.0, moz:headless: false, moz:processID: 795608, moz:profile: C:\Users\alexandru.arcan\Ap..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 76ec390f-dbbe-48c2-be32-931969d81210
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'TAG-614', ip: '10.10.37.89', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: driver.version: unknown
Can someone please point me in the right direction?
Found a solution by implementing myUploadFile method:
...
import net.thucydides.core.pages.components.FileToUpload;
public class PerformTheUpload implements Task {
private WebDriver driver;
public PerformTheUpload (WebDriver driver){
this.driver = driver;
}
public static PerformTheUpload onTheField(WebDriver driver) {
return instrumented(PerformTheUpload.class, driver);
}
#Override public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(WaitUntil.the(UPLOAD_SOURCE_FILES_TARGET, isVisible()));
myUploadFile(driver);
}
public void myUploadFile(WebDriver driver){
WebElement webElement = getUploadWebElementById("uploadSourceFiles", driver);
FileToUpload fileToUpload = new FileToUpload(driver, TEST_FILE);
fileToUpload.fromLocalMachine().to(webElement);
}
}
//in the page class
public static WebElement getUploadWebElementById(String id, WebDriver driver) {
return driver.findElement(By.id(id));
}
I'm getting the below error while page transition, by clicking on submit button. It looks like there was an issue with the newest Chrome release. Without the disable-gpu Chromeoption set, the renderer will occasionally timeout. The workaround until Google fixes this (if they do fix it at all) is to add the --disable-gpu attribute to the ChromeOptions.
Error-message:
Launching the chrome driver
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 8737
Only local connections are allowed.
Aug 22, 2018 10:02:06 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[1534912350.875][SEVERE]: Timed out receiving message from renderer: 20.000
[1534912350.881][SEVERE]: Timed out receiving message from renderer: -0.010
iiiiiiiiiiiiiiiiiii
[1534912370.909][SEVERE]: Timed out receiving message from renderer: 20.000
[1534912370.909][SEVERE]: Timed out receiving message from renderer: -0.001
Exception in thread "main" org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z'
System info: host: 'LAPTOP-B3DIN1KF', ip: '192.168.43.235', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.41.578737 (49da6702b16031..., userDataDir: C:\Users\ACER-S~1\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:49380}, 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: 68.0.3440.106, webStorageEnabled: true}
Session ID: b3de58666d2ca24706dc70a9d78094e4
*** Element info: {Using=css selector, value=body > div > div > div > h1 > a}
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: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:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:322)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:416)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:431)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:314)
at demoPackage.Demo.main(Demo.java:102)
Using the script:
package demoPackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Point;
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.edge.EdgeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.codoid.products.exception.FilloException;
/**
* #author Acer-sumit
*
*/
public class Demo {
public static WebDriver driver = null;
public static JavascriptExecutor js;
public static void main(String args[]) throws FilloException, InterruptedException {
System.out.println("Launching the chrome driver ");
// Set the chrome driver exe file path
System.setProperty("webdriver.chrome.driver","E:\\selenium_sumit\\chromedriver_win32_2.40\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-gpu");
options.addArguments("--disable-browser-side-navigation");
// Instantiate the chrome driver
driver = new ChromeDriver(options);
///System.setProperty("webdriver.edge.driver","E:\\MicrosoftWebDriver.exe");
//driver = new EdgeDriver();
//driver.manage().timeouts().implicitlyWait(6000, TimeUnit.MILLISECONDS);
driver.manage().timeouts().pageLoadTimeout(20,TimeUnit.SECONDS);
//driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
// set the browser URL in get() to load the webpage
try {
driver.navigate().to("https://diggza.com/");
driver.findElement(By.cssSelector("input[name='url']")).clear();
driver.findElement(By.cssSelector("input[name='url']")).sendKeys("https://www.google.com/");
driver.findElement(By.cssSelector("input[name='email']")).sendKeys("sdsjsnssk#gmail.com");
driver.findElement(By.cssSelector("#myform > p:nth-child(5) > a:nth-child(1)")).click();
//wait for element to be visible and perform click
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='submit']")));
js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", driver.findElement(By.cssSelector("input[type='submit']")));
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("iiiiiiiiiiiiiiiiiii");
driver.findElement(By.cssSelector("body > div > div > div > h1 > a")).click();
//driver.navigate().refresh();
}
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("-------fffffffffff---------");
driver.get("https://diggza.com/");
driver.findElement(By.cssSelector("input[name='url']")).clear();
driver.findElement(By.cssSelector("input[name='url']")).sendKeys("https://www.google.com/");
driver.findElement(By.cssSelector("input[name='email']")).sendKeys("sumit.pradhan96#gmail.com");
driver.findElement(By.cssSelector("#myform > p:nth-child(5) > a:nth-child(1)")).click();
//wait for element to be visible and perform click
//wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='submit']")));
driver.findElement(By.cssSelector("input[type='submit']")).click();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}
OS : Windows 10
Browser : Firefox 61
Selenium Version 3.13
Code :
package PhpTravelsPackage;
//import java.awt.List;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
public class phpTravels {
public static void main (String args[]) {
System.setProperty("webdriver.gecko.driver","C:\\\\Marionette\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.DEBUG);
WebDriver driver = new FirefoxDriver(options);
driver.get ("https://www.phptravels.net/");
WebElement link = null;
int linksCount = 0 ;
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("li_myaccount"))).perform();
}
}
Error :
(Program successfully opens the website, but does not perform the action instructed)
Exception in thread "main" org.openqa.selenium.WebDriverException: TypeError: rect is undefined
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.7', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 61.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 9652, moz:profile: C:\Users\admin\AppData\Loca..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: a8b8b5b6-d384-4c35-80f6-9d32bdaa428c
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: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 org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:614)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:594)
at PhpTravelsPackage.phpTravels.main(phpTravels.java:30)
If you want to click on My account button after opening the URL, Then you can try this code:
Note that this id li_myaccount is not unique. There are two web element present in DOM.
WebElement myAccount = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#id='collapse']/descendant::ul[3]/li[#id='li_myaccount']/a")));
myAccount.click();
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.