autotester icon indicating copy to clipboard operation
autotester copied to clipboard

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

Open handita opened this issue 5 years ago • 3 comments

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..

handita avatar Jan 29 '19 03:01 handita

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

new Run().runSnippets([
  {code: 'test.it(...)', path: 'test.js'}
])

vitalets avatar Jan 29 '19 15:01 vitalets

@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>

handita avatar Jan 30 '19 08:01 handita

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

vitalets avatar Jan 31 '19 10:01 vitalets