vitalets / autotester

Chrome extension that allows to develop and run automation tests right in browser
MIT License
169 stars 25 forks source link

How to use this project in my own chrome extension?? #11

Open handita opened 5 years ago

handita commented 5 years ago

Hello, I want to use this project in my own chrome extension, I have already include this two files in my

<script src="js/background/bundle.js"></script>
<script src="js/background/boot.js"></script>
<script src="js/background/mocha.js"></script>

I extract the file in one place, I don't know how to integrate the code so I want to include only code maybe like this with jquery:

 $('#send_button').click(function(){
     var driver;

  test.before(function () {
    driver = new Driver();
  });

  test.after(function () {
    driver.quit();
  });

  test.it('should append query to title', function() {
    driver.get('http://www.google.com');
    driver.findElement(By.name('q')).sendKeys('kitten');
    driver.sleep(1000);
    driver.findElement(By.name('q')).sendKeys(Key.ENTER);
    driver.wait(until.titleContains('kitten'), 2000);
    driver.sleep(1000);
  });
test.run();//maybe this code I want to run right way in my button

// I want to test.run() or something so in my extension I can automate right way.. });

So I don't want to use the editor, and how to execute right way to execute command ??? I know the code use react, but how to integrate with other project..

vitalets commented 5 years ago

I think you can utilize runSnippets() method. E.g.

new Run().runSnippets([
  {code: 'test.it(...)', path: 'test.js'}
])
handita commented 5 years ago

@vitalets can you explain what files should I include in chrome extension??

I'm still having problem, because my file extension cannot detect variable Run in my chrome extension.

Uncaught ReferenceError: Run is not defined

I modify the function like this :

   var code = `test.describe('new_file_3', function () {
  let driver;

  test.before(function () {
    driver = new Driver();
  });

  test.after(function () {
    driver.quit();
  });

  test.it('should pass', function () {
    driver.get('https://google.com');
    driver.wait(until.titleContains('Google'), 2000);
  });
});`;
new Run().runSnippets([
    { code: code, path: 'test.js' }
]);

I include all three files..

 <script src="js/background/bundle.js"></script>
 <script src="js/background/boot.js"></script>
 <script src="js/background/mocha.js"></script>
vitalets commented 5 years ago

To use modules inside your extension you should require files from autotester and build with webpack (instead of using <script> tag). E. g.:

// your-extension-bg.js

const Run = require('...autotester/src/run');

...

Example of using Run module is here: https://github.com/vitalets/autotester/blob/master/src/background/tests-run.js