0

I have started learning WebDriverJs to test websites using Javascript as scripting language from url https://code.google.com/p/selenium/wiki/WebDriverJs but found some understanding issue at the beginning.

As per that page, I have to save chrome driver to some path. What is that path? How do that path link to sample below code?

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
   withCapabilities(webdriver.Capabilities.chrome()).
   build();

driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
 return driver.getTitle().then(function(title) {
   return title === 'webdriver - Google Search';
 });
}, 1000);

driver.quit();

Installing from NPM

% npm install selenium-webdriver

Building from Source

 % git clone https://code.google.com/p/selenium/  
      % cd selenium   
     % ./go //javascript/node:selenium-webdriver

What is NPN and related codes? Kindly explain.

P.S. : I am basically from .Net background

Do I need to do any more setting to run the above code?

For example, any javascript files etc


Now I am able to install selenium-webdriver then I copied above javascript code in js file and tried to run it using node and received below error. Am I missing something?

Error while trying to run above javascript code using node

Community
  • 1
  • 1
Ravi Kanasagra
  • 591
  • 1
  • 8
  • 22
  • This should answer your question (http://stackoverflow.com/questions/13724778/how-to-run-selenium-webdriver-test-cases-in-chrome) – Sakshi Singla Nov 25 '14 at 11:54
  • Thank you Sakshi for your comments. But I require example for Javascript code to write automation code. – Ravi Kanasagra Nov 25 '14 at 12:31
  • var webdriver = require('selenium-webdriver'); var driver = new webdriver.Builder(). withCapabilities(webdriver.Capabilities.chrome()). build(); driver.get('http://www.google.com'); – Sakshi Singla Nov 26 '14 at 04:49
  • @Sakshi - My understand was that above code was written in javascript not in Java. Please correct me if i m wrong. – Ravi Kanasagra Nov 26 '14 at 04:55
  • @Sakshi - Can you tell me what diffrent javascript libraries and other package I need to an into my javascript Selenium WebDriver project to work your example as I did not see any detailed description on internet. – Ravi Kanasagra Nov 26 '14 at 04:57
  • FYI, npm is a package manager. You can install different packages using npm. You can refer http://howtonode.org/introduction-to-npm to get more insight into npm – Sakshi Singla Nov 26 '14 at 05:08
  • @Sakshi - I do not know what npm is. I am from .net background and work on Visual Studio in Windows machine. I was refering to link in the question assuming it has example for javascript as scripting language for selenium. Please help me with some detail ionformation like how to start, what library I need to refer and any setup required etc. I am totally new here. – Ravi Kanasagra Nov 26 '14 at 07:30
  • Ravi, there is a lot of information on internet to know what npm is. Background does not matter here. You need to get to atleast some point and then ask specific questions please – Sakshi Singla Nov 26 '14 at 08:40
  • My point here is to create a sample test from selenium using javascript. Is it necessary to use npm? Do we have other straight forward way? like put libraries, reference executable to some folder location. Something I can do from Visual Studio. – Ravi Kanasagra Nov 26 '14 at 09:50
  • 1
    As far as I know, You will need to use npm and node for installations. After that, you can use your code to start testing from Visual Studio. Node is a pre-requisite for using npm. As mentioned in the webdriverJS link, (requires Node v0.8+). Download node from http://nodejs.org/. Then proceed with instruction in the webdriverJS link – Sakshi Singla Nov 26 '14 at 10:13
  • Then proceed with instruction in the webdriverJS link and the javascript code in your question(Earlier I misread the code as Java. But the code u have is javascript).My bad! – Sakshi Singla Nov 26 '14 at 10:19
  • @Sakshi - I have successfully installed node js in windows. After that I was trying to install selenium webdriver and received error as mentioned in the link http://stackoverflow.com/questions/27149177/error-in-npm-for-npm-install-selenium-webdriver Please do suggest. – Ravi Kanasagra Nov 27 '14 at 05:24
  • 1
    I commented in the mentioned link. Is tht wrkng for you? – Sakshi Singla Nov 27 '14 at 05:52
  • After doing that, I have successfully installed selenium webdriver using npm. – Ravi Kanasagra Nov 27 '14 at 06:42
  • After creating folder, installation works fine in my local machine but it is not working in my office machine. Please find the link with details http://stackoverflow.com/questions/27165638/network-error-while-installing-selenium-webdriver-package-using-npm – Ravi Kanasagra Nov 27 '14 at 07:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65808/discussion-between-sakshi-singla-and-ravi-kanasagra). – Sakshi Singla Nov 28 '14 at 07:05
  • Are you able to see the conversation in chat? – Sakshi Singla Nov 28 '14 at 07:28

1 Answers1

1

You seem to have a problem with the folder structure.

The How do I resolve "Cannot find module" error using Node.js? should help you resolve your issue

Community
  • 1
  • 1
Sakshi Singla
  • 2,462
  • 1
  • 18
  • 34
  • I received one more issue. Could you please have a look at this link http://stackoverflow.com/questions/27224959/getting-error-while-trying-to-run-example-test-of-selenium-webdriver – Ravi Kanasagra Dec 01 '14 at 09:10