Link to home
Start Free TrialLog in
Avatar of Sascha Koeth
Sascha KoethFlag for Germany

asked on

How to run a selenium script from within wordpress

Hi!

I want to run a selenium script from within the wordpress environment. How can I format the script so I can trigger it simply by linking to the scripts URL?

Here is the example of how I can pre-format the selenium script:

import { browser, by, element, Key, logging, ExpectedConditions as EC } from 'protractor';

describe('Second', () => {

   beforeAll(async () => { });
   beforeEach(async () => { });

   it('should do something', async () => {
      await browser.get('https://spehzies.de/wp-admin/edit.php?post_type=page');
      await element(by.xpath("//li[@id='toplevel_page_migrateguru']/a/div[3]")).click();
      await element(by.id("email")).click();
      await element(by.id("email")).sendKeys('s.koeth@haywood.de');
      await element(by.xpath("//div[@id='wpbody-content']/div[4]/div[2]")).click();
      await element(by.name("consent")).click();
      await element(by.id("migratesubmit")).click();
      await element(by.xpath("//div[@id='app']/span/div/div/div[2]/form/div/div/div/div[14]/span[2]")).click();
   });

   afterEach(async () => {
      // Assert that there are no errors emitted from the browser
      const logs = await browser.manage().logs().get(logging.Type.BROWSER);
      expect(logs).not.toContain(jasmine.objectContaining({
         level: logging.Level.SEVERE,
      } as logging.Entry));
   });

});

Open in new window

Additionaly to that I could also format it with these options:

User generated image
So to make the objective more clear: I do not want to do testings by using any of those testing platforms. I simply want to run the script once the URL is called, without having to have any kind of platform accounts.

Thanks!

Sascha
Avatar of David Favor
David Favor
Flag of United States of America image

Trying to understand your question.

With Selenium...

1) You setup a Selenium instance somewhere.

2) Or use an online Selenium service.

3) You execute a Selenium script to emulate an interaction with a Website.

4) Unsure exactly what "run a selenium script from within the wordpress environment" might mean, as Selenium + WordPress are 2x different beasts.

Maybe expand your question a bit, starting with where your Selenium instance is running + whether you setup Selenium yourself or are using a service.

If you mean actually... somehow have WordPress emulate Selenium... you'll have to somehow port the Selenium code to fuse it into WordPress... A daunting task...
Avatar of Sascha Koeth

ASKER

So I have a chrome extension like:

Katalon Recorder
Wildfire
UI.Vision

Then I interact with my wordpress admin page and by that record a selenium script.

Now those selenium scripts can be "rerun" by the chrome extensions.

Now I want to run the script indipendantly from those chrome extensions, so on a browser that does not have those extensions installed.

And as they offer export functions I kind of imagined that there are open source "libraries" you can load with lets say javascript and which enable the browser to understand and trigger those selenium funcitons.

Does that make any sense to you?
After further investigating and reading your answer a second time I guess I need to find a way to setup NodeJS, Selenium WebDriver, the ChromeDriver and the GeckoDriver for Firefox on my Server as a first step and then try to find a way to run those "flows" by using a "trigger URL"... so that the script excecution and the wordpress environment are completly separated. The only "connection" is the Trigger URL send from a wordpress admin page.
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks! I never did a "container" installation before, but I guess that´s another threat.
You're welcome!

I generally place every Site/App/API in it's own container, so management + movement + backups/restores are easy.

Also security is stellar, as one container hacked remains contained to the container, never leaking across massive amounts of code.