io.cucumber.java.PendingException: TODO: implement me
The above error message is displaying while I run my test case.
Browser opened and access the specified URL. After that I'm getting this error.
Can someone help.
#Given("Access the website")
public void access_the_website() throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C://Users//Jayalekshmi//Desktop//Automation//chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("URL");
// Write code here that turns the phrase above into concrete actions
System.out.println("heloo");
throw new io.cucumber.java.PendingException();
}
#Given("Click Login option")
public void click_login_option() throws InterruptedException {
driver.wait();
System.out.println("Hiiii");
driver.findElement(By.xpath("/html/body/div[1]/header/div/div/div[2]/div/div/a[1]")).click();
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
My browser opened and window maximized and access the URL.
After that I'm getting error.
After accessing the URL, I'm expecting to click on the Login option available on the website.
Just remove this part:
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
This is added automatically in case you forget to implement the step definition.
Related
getting exception
FAILED CONFIGURATION: #AfterClass tearDown
"org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource"
enter code here
public class BaseClass {
//read config file and initiate variables
ReadConfig readConfig = new ReadConfig();
public String username = readConfig.getUserName();
//public String password = "asas";
public String password = readConfig.getPassword();
public static AppiumDriver driver;
public static org.apache.logging.log4j.Logger logger;
#BeforeClass
public void setUp ()
{
try {
logger = LogManager.getLogger(BaseClass.class);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "bd178829");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.APP, "D:\\automation\\CRMNextMobileAutomation\\src\\test\\resources\\apps\\CRMNextNative 6.29.0-release_screenshot_enabled.apk");
dc.setCapability("automationName","UiAutomator2");
dc.setCapability("appPackage", "com.crmnextmobile.crmnextofflineplay");
dc.setCapability("appActivity", "com.crmnextmobile.crmnextofflineplay.qr.QrScannerActivity");
dc.setCapability("enforceAppInsall", true);
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AppiumDriver(url,dc);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
System.out.println("CRMNext automation start..");
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
//Clicking on Allow option on open permission pop up
//driver.findElement(By.id("com.android.permissioncontroller:id/permission_allow_button")).click();
if(!driver.findElements(By.id ("com.android.permissioncontroller:id/permission_allow_button")).isEmpty()){
//THEN CLICK ON THE SUBMIT BUTTON
System.out.println("permission_allow_button is found on page");
driver.findElement(By.id("com.android.permissioncontroller:id/permission_allow_button")).click();
}else{
//DO SOMETHING ELSE AS SUBMIT BUTTON IS NOT THERE
System.out.println("permission_allow_button not found on page");
}
//Clicking on Allow button of run in background pop up
//driver.findElement(By.id("android:id/button1")).click();
if(!driver.findElements(By.id ("android:id/button1")).isEmpty()){
//THEN CLICK ON THE SUBMIT BUTTON
System.out.println("button1 is found on page");
driver.findElement(By.id("android:id/button1")).click();
}else{
//DO SOMETHING ELSE AS SUBMIT BUTTON IS NOT THERE
System.out.println("button1 not found on page");
}
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
Thread.sleep(5000);
System.out.println("CRMNext automation Before Skip..");
//Clicking on Skip button
driver.findElement(By.id("com.crmnextmobile.crmnextofflineplay:id/skip")).click();
System.out.println("CRMNext automation after Skip..");
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
Thread.sleep(10000);
driver.findElement(By.id("com.crmnextmobile.crmnextofflineplay:id/relative_layout_continue")).click();
Thread.sleep(2000);
} catch (Exception exp) {
// TODO: handle exception
System.out.println("Cause is :"+exp.getCause());
System.out.println("Message is :"+exp.getMessage());
exp.printStackTrace();
}
}
#Test
public void sample() {
System.out.println("Sample run");
}
#AfterClass
public void tearDown()
{
driver.close();
driver.quit();
}
//org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
all tests are failing due to this.
driver.close()
The driver.close() command is used to close the current browser window having focus. In case there is only one browser open then calling driver.close() quits the whole browser session.
Usability
Use driver.close() when dealing with multiple browser tabs or windows e.g. when clicking on a link that opens another tab. In this case after performing required action in the new tab, to close the tab, call the driver.close() method.
driver.quit()
The driver.quit() is used to quit the whole browser session along with all the associated browser windows, tabs and pop-ups.
Usability
Use driver.quit() when no longer want to interact with the driver object along with any associated window, tab or pop-up. Generally, it is the last statements of the automation scripts. Call driver.quit() in the #AfterClass method to close it at the end of the whole suite.
Use following code in #AfterClass
#AfterClass
public void tearDown()
{
if (driver != null)
driver.Quit();
}
I am trying to integrate the Extent Reports with Selenium WebDriver Event listeners so that after every action (like navigateTo, clickon, elementChangeValue, etc) the logs get added to the extent report for every action and exceptions. Any thoughts on how can I achieve this since I think I cant pass the EventTest object as a parameter in extended/implemented WebDriverEventListener's methods.
I don't know if that is possible but you can create you own methods for navigateTo, clickon, elementChangeValue, etc and add the actions like steps in the extent report.
For example:
public void navigateTo(String url) throws Exception {
driver.get(url);
try {
driver.findElement(By.className("some_element_in_page"));
TestListener.getExtentTest().log(Status.INFO, "Login successful");
} catch (Exception e) {
TestListener.getExtentTest().log(Status.FAIL, "Login failed");
}
}
Here is a tutorial that might help you.
I am new to Selenium, While practicing I come up with one issue, I am doing testing for my own application which has been deployed in tomcat server. So after opening my application I am testing validations in one method and page change in one method. Now My point is I am doing both testing for my both methods at same page.
Why do I need to write same code both methods,
driver.get("http://localhost:8070/");
driver.findElement(By.xpath("//div[#id='actions']/div[2]/a/span")).click();
driver.findElement(By.linkText("/ReportGenerator")).click();
How can I directly perform operations, If I remove above two lines in my second method It is getting failed. How to solve this?
#Test
public void analysisValidation()
{
driver.get("http://localhost:8070/");
driver.findElement(By.xpath("//div[#id='actions']/div[2]/a/span")).click();
driver.findElement(By.linkText("/ReportGenerator")).click();
driver.findElement(By.id("Analysis")).click();
WebElement webElement = driver.findElement(By.id("modelForm.errors"));
String alertMsg = webElement.getText();
System.out.println(alertMsg);
Assert.assertEquals("Please select a Survey Id to perform Aggregate Analysis", alertMsg);
}
#Test
public void testAnalysisPage()
{
driver.get("http://localhost:8070/");
driver.findElement(By.xpath("//div[#id='actions']/div[2]/a/span")).click();
driver.findElement(By.linkText("/ReportGenerator")).click();
new Select(driver.findElement(By.id("surveyId"))).selectByVisibleText("Apollo");
driver.findElement(By.id("Analysis")).click();
System.out.println(driver.getTitle());
String pageTitle = driver.getTitle();
Assert.assertEquals("My JSP 'analysis.jsp' starting page", pageTitle);
}
How can I directly perform operations, If I remove above two lines in
my second method It is getting failed. How to solve this
The tests fail because each #Test test is executed independently. The code you remove is needed to initialize the driver and load the page.
You can fix this as follows:
Create a function, setUp() with the #beforemethod annotation. Populate it with the driver initialization and loading-page calls.
Create a function, teardown() with the #AfterMethod annotation. Populate it with the driver cleanup calls.
For example, here is some pseudocode (modify this as per taste)
#BeforeMethod
public void setUp() throws Exception {
driver.get("http://localhost:8070/");
driver.findElement(By.xpath("//div[#id='actions']/div[2]/a/span")).click();
driver.findElement(By.linkText("/ReportGenerator")).click();
}
#AfterMethod
public void teardown() throws Exception {
driver.quit()
}
The advantage of the #BeforeMethod and #AfterMethod annotations is that the code will be run before / after each #Test method executes. You can therefore avoid having to duplicate your code.
I am testing a web App which contains phone/voice verification in one process flow, I am trying to automate this verification process. My Query is:
Is there any way to do it manually like for example entering phone(text)/voice code manually when occurs, while enter code the thread sleeps or wait 'until ExpectedConditon'?
For example: we'll do in the case when the page is in processing phase so, we use
wait.until(ExpectedConditions.presenceOfElementLocated(By.some selector));
it will wait for certain 'timeOutSeconds'.
thanks in advance..........
This is a simple example that i wrote that i'll think it's going to suit your need. In this code the driver starts opening Google. Once the page fully loads the console waits for the input data on the console (i.e. http://www.stackoverflow.com).
This code will probably solve your issue with the manual input during test run.
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
InputStreamReader istream = new InputStreamReader(System.in);
BufferedReader bufRead = new BufferedReader(istream);
String nextWebSite = "http://www.google.com";
driver.get(nextWebSite);
try {
System.out.println("What's the next Website you'll like to visit? ");
nextWebSite = bufRead.readLine();
} catch (IOException err) {
System.out.println("Sorry, there was a problem reading the informed data");
}
driver.get(nextWebSite);
driver.close();
driver.quit();
}
I need to read alert & confirmation messages displayed in pop ups using java and print it on the console. On export of the selenium recording from the IDE as a Junit4 (WebDriver) java file, my code is:
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
Now when I tried to use getAlert or getConfirmation functions as shown:
#Test
public void testSample() throws Exception {
Alert alert = driver.switchTo().alert();
message = alert.getText();
System.out.println("message is "+message);
}
I get the following error:
java.lang.NullPointerException
at com.example.tests.Sample.testSample(Sample.java:40)
at com.example.tests.Sample.main(Sample.java:149)
Exception: null
How do I handle this? Also is there any other way of reading the pop up messages?
In the testSample() method when you navigate to any page by using -
driver.get("URL");
After that can you explain how the alert message comes up in the 1st place.
Are you sure that the pop up message which appears is a javascript alert or any window which is opening up.
If it is a an alert message then you can access it by using -
driver.switchTo().alert();
But if the pop up is another window then you will have to use -
driver.switchTo().window("windowName");
You can get more information about this from here.