Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Quality Assurance Introduction to Selenium Automation Nation Page Object Model

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,845 Points

Selenium runs tests then automatically closes the browser

Hi all,

Here's a problem.

I've got my finished code which successfully runs the tests, but then promptly closes the browser. I don't think it's a problem with code, maybe I need to update Selenium Web Driver?

debug.log
[0926/152756.483:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights.  (0xc0000022)
[0926/152756.552:ERROR:exception_snapshot_win.cc(87)] thread ID 7616 not found in process
[0926/152756.552:WARNING:crash_report_exception_handler.cc(62)] ProcessSnapshotWin::Initialize failed
index.js
//import seleniun package
const selenium = require("selenium-webdriver");

//require browser driver for google Chrome
require("chromedriver");

//use Selenium By Library
const By = selenium.By;

const HomePage = require("./pages/home");

//build pattern to access webpage.
const driver = new selenium.Builder()
   .forBrowser("chrome")
   .build();

const homePage = new HomePage(driver);
homePage.open();

//array of invitees
const invitees = [
    'Gonzalo Torres del Fierro',
    'Shadd Anderson',
    'George Aparece',
    'Shadab Khan',
    'Joseph Michael Casey',
    'Jennifer Nordell',
    'Faisal Albinali',
    'Taron Foxworth',
    'David Riesz',
    'Maicej Torbus',
    'Martin Luckett',
    'Joel Bardsley',
    'Reuben Varzea',
    'Ken Alger',
    'Amrit Pandey',
    'Rafal Rudzinski',
    'Brian Lynch',
    'Lupe Camacho',
    'Luke Fiji',
    'Sean Christensen',
    'Philip Graf',
    'Mike Norman',
    'Michael Hulet',
    'Brent Suggs'
 ];

//perform actions
//addInvitee("first name");
//addInvitee("last name");

//invitees.forEach(invitee => homePage.addInvitee(invitee));
invitees.forEach(homePage.addInvitee, homePage); 

//call the functions

homePage.removeInvitee("Shadd Anderson");

homePage.toggleNonRespondersVisibility();
home.js
const By = require("selenium-webdriver").By;

class HomePage {

    constructor(driver) {
        //store reference to the driver in instance
        this.driver = driver;
        //JavaScript Object Literal
        this.locators = {
            inviteeForm: By.id("registrar"),
            inviteeNameField: By.name("name"),
            toggleNonRespondersVisibility: By.css(".main > div input"),
            removeButtonForInvitee: invitee => By.xpath(`//span[text() = "${invitee}"]/../button[last()]`)

        };

    }

    open() {
        //open URL
        this.driver.get(process.env.URL);
    } 

    //keep it DRY with functions
    addInvitee(name) {
        this.driver.findElement(this.locators.inviteeNameField)
            .sendKeys(name);
        this.driver.findElement(this.locators.inviteeForm).submit();

    }

    removeInvitee(invitee) {
        this.driver.findElement(this.locators.removeButtonForInvitee(invitee))
        .click();
    }

    toggleNonRespondersVisibility() {
        this.driver.findElement(this.locators.toggleNonRespondersVisibility)
        .click();
    }
}

module.exports = HomePage;
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 90,845 Points

I did just test this on my laptop, having done a git pull on the project.

The test seems to have run properly and not crashed the browser. I've verified also that it did not add anything new to the npm.debug file.

I must have done something to the configuration on my PC that changed something but I can't think what. I know you're not all mind readers but any thoughts? Help :)??

Craig Dennis

1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 90,845 Points

Hi Linda, I’m sorry I seemed to have missed this answer. But I’ll make a point To try it out, I don’t think the course used it but it can’t hurt to try :)