0

I am facing this kind of problem : Test "before each" hook: ret for "Test Case": Error: Timeout of 50000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

2) Test "after each" hook: ret for "Test Case": Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

        var webdriver=require('selenium-webdriver');
var By=require('selenium-webdriver').By;
var until=require('selenium-webdriver').until;

//this requires to include the mocha describe,each.....
var test = require('selenium-webdriver/testing');

var fs=require('fs');

var chrome = require('selenium-webdriver/chrome');
var path = require('chromedriver').path;

var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.chrome())
    .build();


test.describe( 'Test' , function(){

    test.beforeEach(function(){
        this.timeout(50000); 

        driver.get('https://staging.keela.co/login');

    });

    test.afterEach(function(){
        driver.quit();
    });

    test.it( 'Test Case' , function(){
    this.timeout(50000);
  setTimeout(done, 4000);
        // driver.findElement(webdriver.By.xpath('//*[@id="login-email"]')).then(function(title){
        //     title.sendKeys("bandana@yopmail.com");

     driver.wait(until.elementLocated(By.name('login-email'))).then(function(email){
     email.sendKeys('bandanakeela@gmail.com');

     driver.wait(until.elementLocated(By.name('login-password'))).then(function(pw){
     pw.sendKeys('123456789');
        });

     driver.findElement(webdriver.By.linkText("Log In")).click();

        });
    });

});
Bandana Singh
  • 95
  • 1
  • 4
  • 10

2 Answers2

0

I noticed that there is quite a delay between the time that the page opens and the time that the login form becomes available to interact with. Your code does not wait for the controls to become clickable.

I don't know the way you would do this with Javascript, but in Python, you would use the WebDriverWait object.

As an aside, it MAY be more reliable to use the "id" attribute, rather than the "name".

Breaks Software
  • 1,721
  • 1
  • 10
  • 15
0

A couple of facts :

  • Change the locator for Email field as :

    return driver.findElement({xpath:"//input[@class='form-control' and @id='login-email']"});
    
  • Change the locator for Password field as :

    return driver.findElement({xpath:"//input[@class='form-control' and @id='login-password']"});
    
  • The elements on the webpage e.g. Email and Password field are getting rendered a while after the document.readyState === "complete" is achieved. So induce WebDriverWait for the Email field with ExpectedConditions set to elementToBeClickable(By locator).

    (Java)
    WebElement my_email = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='form-control' and @id='login-email']")));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried but its still same & I even tried by using webdriverjs mocha but also same error – Bandana Singh Jan 11 '18 at 10:01
  • See this `https://stackoverflow.com/questions/46202283/exception-in-thread-main-org-openqa-selenium-nosuchelementexception-unable-to` your own issue :) Upvote that Answer if that was useful to you. In this case just introduce `WebDriverWait` in `Javascript` format. – undetected Selenium Jan 11 '18 at 10:09
  • Now,I am trying with webdriverjs mocha and over there I am facing problem like: Error: Timeout of 50000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. – Bandana Singh Jan 11 '18 at 10:47
  • Can you update the Question with the full error stack trace? – undetected Selenium Jan 11 '18 at 10:49