I am in the process of setting up my environment for headless testing using Selenium and PhantomJS.
Getting PhantomJS Ready:
To start, I created a folder named c:/phantomjs
and downloaded all the necessary PhantomJS script files into it.
Next, I set up another folder called C:\xampp\htdocs\testPhantomJS
.
After that, I installed nodeJS on my system.
Moving on, I navigated to the command prompt at C:\xampp\htdocs\testPhantomJS
and proceeded to install PhantomJS with the following command:
C:\xampp\htdocs\testPhantomJS>npm install -g phantomjs
It's worth noting that the image attached shows a different location because it was taken from my colleague's computer. We are working on the same installation, which is why there is a discrepancy in the folder locations. Rest assured, the location I specified is where I completed the setup.
https://i.sstatic.net/kS0PQ.jpg
Now, when I type "phantomjs" in the command prompt, I get:
C:\xampp\htdocs\testPhantomJS>phantomjs
phantom>
Configuring Selenium-Webdriver
Similarly, I navigated to C:\xampp\htdocs\testPhantomJS
in the command prompt and installed selenium webdriver with this command:
C:\xampp\htdocs\testPhantomJS>npm install selenium-webdriver
https://i.sstatic.net/UyZqs.png
Once the installation is complete, the folder structure looks like this: https://i.sstatic.net/ivJMl.png
Now, I have a test script named test.js
, structured as follows:
describe('Test example.com', function(){
before(function(done) {
client.init().url('http://google.com', done);
});
describe('Check homepage', function(){
it('should see the correct title', function(done) {
client.getTitle(function(err, title){
expect(title).to.have.string('Example Domain');
done();
});
});
it('should see the body', function(done) {
client.getText('p', function(err, p){
expect(p).to.have.string(
'for illustrative examples in documents.'
);
done();
})
});
});
after(function(done) {
client.end();
done();
});
});
The challenge I'm facing now is figuring out where to place the above script and how to execute it. I don't just want to run it using PhantomJS; I also need to test it with both PhantomJS and Selenium.