Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Second test doesnt change URL

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 ?

like image 286
user49126 Avatar asked Oct 19 '16 15:10

user49126


1 Answers

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)

like image 95
iamdanchiv Avatar answered Sep 27 '22 18:09

iamdanchiv