6

I have two test. The first test passes successfully. Then there is an url method call in the second test, but it doesn't change the url in the browser.

The baseUrl in wdio.conf.js is set to http://localhost/web/es/index.html#

Tests:

var assert = require('assert');

describe('user login ', function(){

    it('user login', function(){

        browser
            .url('/system/login')
            .setValue('[name="username"]','test')
            .setValue('[name="password"]','test')
            .click('=Potvrď');            

        assert(browser.waitUntil('=test test'));                
    });

    it('user form', function(){

        browser
            .url('/user/form');
    });
});

In the first test /system/login is opened correctly. But in the second test the url never changes to /user/form

I'm just starting with webdriverio so am i missing something ?

vsync
  • 87,559
  • 45
  • 247
  • 317
user49126
  • 1,669
  • 6
  • 27
  • 44
  • 1
    Sidenote : your jasmine tests should be more explicit. "user login - user form" seems ok for you *now*, but will it be in 6 months, or to another user? – Alex Nov 05 '16 at 01:27
  • My standalone webdriverio experiments ended up with a similar issue, even though I used absolute URLs. Using `.reload().setViewportSize({...}).url()...... .end()` worked for me, but I did not find the root cause of the issue. – eel ghEEz May 07 '18 at 16:07

3 Answers3

0

Check the condition on browser.waitUntil(...). The first parameter is a function according to http://webdriver.io/api/utility/waitUntil.html.

Also, adding a timeout (3seconds) will help to see if the wait has been successful.

browser.waitUntil(function() {
   return browser.getText('#some_id') === 'test test';
}, 3000, "Timeout!!");
jordiburgos
  • 4,742
  • 3
  • 38
  • 65
0

That is because it's not really a test. What are you testing, where is your acceptance criteria? You told the browser to do something and didn't wait to check up on it. It's basically like you said: Selenium, do this and I don't care I am done, bye.

What you can use? Try giving it a pause: .pause(ms); give it 10000 (10s) and visually see if it changes. you can also add an additional: .getUrl() - to get the URL after the time stated under ms.

Alternatively (instead of the things stated above): On your new URL, is there an element in DOM that is not present in the DOM on old URL? If so, add to the end:

.waitForExist(selector, ms); give it 1000 under ms, and make sure you got the right selector for that element

This way browser will wait for that element to appear.

DanteTheSmith
  • 2,193
  • 1
  • 9
  • 27
0

A lot of time passed since @user49126 asked the question, but since no one actually saw that this is in fact a routing issue, here is my answer:

It looks like you are using a bad baseUrl value. You have to go back and re-read it's description in the wdio.config.js file. Any value you pass to the browser.url() function will be postpended to your baseURL.

In your case, firstly you are going to http://localhost/web/es/index.html# + /system/login, which due to the # and probably your routing logic behind, evaluates correctly to a valid route. The second test most surely takes you to an invalid route. In order to completely isolate your issue we will need the console output.

Here is the setup I used to debug this:

wdio.config.js:

// Set a base URL in order to shorten url command calls. If your url parameter starts
// with "/", then the base url gets PREPENDED.
baseUrl: ' http://127.0.0.1:8303',

Code:

describe("\nDebug routing issue", function() {

it("\nShould verify the URL, click something, move on\n", function() {
    return browser
        .url('/product-page.html')
        .getUrl()
        .then( function(retURL) {
            assert.include(retURL, "product-page", "Yeap! You're good!");
        })
        .waitUntil(function() {
             return browser.isVisible("div.top-bar-right a");
         }, 3000, "\nLogin failed...")
        .click('div.top-bar-right a')
        // Casual 'pause' to witness the click
        .pause('1000');
});

it("\nShould reload different URL and validate site routing\n", function() {
    return browser
        .url('/index.html')
        .getUrl()
        .then( function(retURL) {
            assert.include(retURL, "index", "Yeap! You're good!");
        })
        // Casual 'pause' to witness the new route
        .pause('1000')
});

TL;DR: Just make sure you are have the correct value in the baseUrl variable. In your case, change the baseUrl value to http://localhost/.

My suggestion is to also use the port, e.g. http://localhost:8303/, or the IP of your localhost server altogether, as I also experienced some issues using it as simply localhost.

PS: None of the other answers touch upon the real issue the user is experiencing. Unfortunately I have no way to comment/signal this. ('Not enough minera... errrg, rep points,' #feelsbadman)

Community
  • 1
  • 1
iamdanchiv
  • 3,828
  • 4
  • 32
  • 40