D
D
dr sbtn2017-08-14 12:51:16
Python
dr sbtn, 2017-08-14 12:51:16

How to "combine" the work of selenium webdriver and pyTest in order to write an autotest for some actions on the site?

Using selenium webdriver and the pytest test framework, I want to "simulate" certain user actions on the site in python.
tell me where to look in order to understand how to implement this through the friendly work of these tools?
I can not find at least some understandable manuals or articles.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dummyman, 2017-08-14
@dummyman

Didn't work with selenium but worked a lot with casper .
The principles must be the same.
How do I do it in Casper?
Let's take a basic example.

var casper = require('casper').create();
var links;

function getLinks() {
// Scrape the links from top-right nav of the website
    var links = document.querySelectorAll('ul.navigation li a');
    return Array.prototype.map.call(links, function (e) {
        return e.getAttribute('href')
    });
}

// Opens casperjs homepage
casper.start('http://casperjs.org/');

casper.then(function () {
    links = this.evaluate(getLinks);
});

casper.run(function () {
    for(var i in links) {
        console.log(links[i]);
    }
    casper.done();
});

It is not necessary to save it to a file in advance, you can run Casper from Python without parameters and it will wait for instructions to the standard input stream.
You shouldn't send the whole script at once. We will send the first batch
var casper = require('casper').create();
var links;

function getLinks() {
// Scrape the links from top-right nav of the website
    var links = document.querySelectorAll('ul.navigation li a');
    return Array.prototype.map.call(links, function (e) {
        return e.getAttribute('href')
    });
}

// Opens casperjs homepage
casper.start('http://casperjs.org/');

After, for example, a second, execute
casper.then(function () {
    links = this.evaluate(getLinks);
});

Let's check the result in a second.
casper.run(function () {
    for(var i in links) {
        console.log(links[i]);
    }
});

Then let's do it again:
casper.thenOpen('http://phantomjs.org', function() {
    this.echo(this.getTitle());
});

casper.then(function () {
    links = this.evaluate(getLinks);
});

And check the result again:
casper.run(function () {
    for(var i in links) {
        console.log(links[i]);
    }
});

And finally, let's finish Casper's work:
Casper also has its own unit testing system .
I'm not sure that it will be more difficult / easier with selenium, the principles are the same everywhere.
See documentation

A
Alexander Bushmanov, 2017-09-02
@assanti

Use the documentation of the framework and webdriver.
Perform initialization, driver setup in the fixture and pass it on to the test in the same form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question