Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Quality Assurance

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Help updating a Selenium Issue?

Okay, so I've had a lot of fun with the great new Selenium Course. But along the way I've had a problem. I encountered a problem I talked about in This thread in which my automated Chrome Browser closed after all the tests were performed.

I finished the course and was able to perform the other REPL tests without the browser closing which seems to tell me that there's not an issue with Selenium per se; but somewhere in the code. But yet, there's no error in the project and the tests run through just fine.

Once again here's the code and contents of debug.log. I'm using Windows 10 Home, ChromeDriver, node 8.4.0 and npm 5.3.0/

index.js
//import seleniun package
const selenium = require("selenium-webdriver");
const fs = require("fs");

//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
    .findInviteeByName("David Riesz")
    .remove();

homePage
    .findInviteeByName("Jennifer Nordell")
    .toggleConfirmation();


//take ss with selenium
driver.takeScreenshot().then((image, error) => {
    fs.writeFile("weird-layout.png", image, "base64",
    err=> console.error(err))
});


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"),
            inviteeByName: name => By.xpath(`//span[text() = "${name}"]/..`)
        };

    }

    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();

    }

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

    findInviteeByName(name) {
        const el = this.driver
            .findElement(this.locators.inviteeByName(name));
        return new Invitee(el);

    }

}


class Invitee {
    constructor(element) {
        this.element = element;
        this.locators = {
          removeButton: By.css("button:last-child"),
          confirmedCheckbox: By.css("input[type='checkbox']")
        };
     }

     remove() {
       this.element
           .findElement(this.locators.removeButton)
           .click();
     }

     toggleConfirmation() {
        this.element
            .findElement(this.locators.confirmedCheckbox)
            .click();

     }
   }


module.exports = HomePage;
[1003/114613.188: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)
[1003/114613.189:ERROR:exception_snapshot_win.cc(87)] thread ID 11448 not found in process
[1003/114613.189:WARNING:crash_report_exception_handler.cc(62)] ProcessSnapshotWin::Initialize failed