好的,尽管我已经学到足够多的知识,但我对硒的了解并不多,我不知道该怎么做。我正在使用docker-compose在快速应用上运行一些摩卡测试。我已经配置了我设置的容器。但是我没有进行硒测试,也不确定要解决什么。
此处提供源代码。
'use strict';
require('geckodriver');
const expect = require('chai').expect;
const webdriver = require('selenium-webdriver');
module.exports = {
shouldBeLiterate: async function(driver) {
await driver.get('http://localhost:3000');
const title = await driver.getTitle();
expect(title).to.equal('LITERATE');
},
centerfoldShouldBeLiterate: async function (driver) {
await driver.get('http://localhost:3000');
const centerfold = await driver.findElement(webdriver.By.id('home-title')).getText();
expect(centerfold).to.equal('LITERATE');
},
searchForString: async function (driver, usrStr) {
await driver.get('http://localhost:3000');
const searchBox = await driver.findElement(webdriver.By.id('queryField')).sendKeys(usrStr);
const searchButton = await driver.findElement(webdriver.By.id('search-button'));
await searchButton.click();
await driver.wait( driver => {
return driver.executeScript('if(window.hasOwnProperty("article-title")) return true;');
}, 10000)
const result = await driver.findElement(webdriver.By.id('article-title')).getText();
expect(result).to.not.be.empty();
},
searchedStringisinDB: async function (driver, usrStr) {
await driver.get('http://localhost:3000');
const searchBox = await driver.findElement(webdriver.By.id('queryField')).sendKeys(usrStr)
const searchButton = await driver.findElement(webdriver.By.id('search-button'));
await searchButton.click();
//maybe check here with postgres database call getMostRecentSearch();
await driver.wait( driver => {
return driver.exectureScript('if(window.hasOwnProperty("article-title")) return true;');
}, 10000)
}
}
在这里进行测试
'use strict';
const literateHome = require('../../src/api/literateHome.src');
const { describeTest } = require('../../utils/start.config');
const webdriver = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
const driver = new webdriver.Builder().forBrowser('firefox').build();
describeTest('Home Page Defaults', function () {
describe('home page texts should be correct', function() {
it('title should be LITERATE', () => literateHome.shouldBeLiterate(driver)).timeout(50000);
it('centerfold should be LITERATE', () => literateHome.centerfoldShouldBeLiterate(driver)).timeout(50000);
}, driver);
describe('home page should search for specified string', function () {
const usrStr = require("../../utils/defaults/string.default.json").string;
it('should search from VIDEO GAMES', () => literateHome.searchForString(driver, usrStr)).timeout(50000);
}, driver)
}, driver);
这里是docker-compose
version: '3'
services:
webapp:
build: ./literate-app
command: nodemon -e vue,js,css start.js
depends_on:
- postgres
links:
- postgres
environment:
- DB_HOST=postgres
ports:
- "3000:3000"
networks:
- literate-net
server:
build: ./readability-server
command: nodemon -L --inspect=0.0.0.0:5555 server.js
networks:
- literate-net
redis_db:
image: redis:alpine
networks:
- literate-net
postgres:
restart: 'always'
#image: 'bitnami/postgresql:latest'
volumes:
- /bitnami
ports:
- "5432:5432"
networks:
- literate-net
environment:
- "FILLA_DB_USER=my_user"
- "FILLA_DB_PASSWORD=password123"
- "FILLA_DB_DATABASE=my_database"
- "POSTGRES_PASSWORD=password123"
build: './database-creation'
test:
image: node:latest
build: ./test
working_dir: /literate-app/test
volumes:
- .:/literate-app
command:
npm run mocha
networks:
- literate-net
depends_on:
- postgres
environment:
- DB_HOST=postgres
hub:
image: selenium/hub:3.14.0-gallium
ports:
- "4444:4444"
networks:
- literate-net
firefox:
image: selenium/node-firefox:3.14.0-gallium
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
networks:
- literate-net
test-ff:
build: ./test
working_dir: /literate-app/test
command: npm run mocha-ff
volumes:
- .:/literate-app
networks:
- literate-net
depends_on:
- postgres
- firefox
- webapp
- server
environment:
HUB_HOST: hub
networks:
literate-net:
driver: bridge
我当前遇到的问题是
SessionNotCreatedError: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
当我尝试将其添加到它时,它就坏了。之所以这样,是因为我们使用的是构建器而不是其他方法。香港专业教育学院试图让它打印出当前的功能。但是,这只是给我一个未完成的承诺。
该应用程序公开了3000端口,我知道硒在4444上运行。当我将硒的URL更改为http://localhost:4444/wd/hub时,它不会更改二进制文件相同的错误。
感谢您对此问题的任何帮助或指导。